Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 // TODO(ager): The only reason for this class is that we | 7 // TODO(ager): The only reason for this class is that we |
| 8 // cannot patch a top-level at this point. | 8 // cannot patch a top-level at this point. |
| 9 class _ProcessUtils { | 9 class _ProcessUtils { |
| 10 external static _exit(int status); | 10 external static _exit(int status); |
| 11 external static _setExitCode(int status); | 11 external static _setExitCode(int status); |
| 12 external static _sleep(int millis); | 12 external static _sleep(int millis); |
| 13 external static int _pid(Process process); | |
| 13 } | 14 } |
| 14 | 15 |
| 15 /** | 16 /** |
| 16 * Exit the Dart VM process immediately with the given [status] code. | 17 * Exit the Dart VM process immediately with the given [status] code. |
| 17 * | 18 * |
| 18 * This does not wait for any asynchronous operations to terminate. Using | 19 * This does not wait for any asynchronous operations to terminate. Using |
| 19 * [exit] is therefore very likely to lose data. | 20 * [exit] is therefore very likely to lose data. |
| 20 */ | 21 */ |
| 21 void exit(int status) { | 22 void exit(int status) { |
| 22 if (status is !int) { | 23 if (status is !int) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 47 */ | 48 */ |
| 48 void sleep(Duration duration) { | 49 void sleep(Duration duration) { |
| 49 int milliseconds = duration.inMilliseconds; | 50 int milliseconds = duration.inMilliseconds; |
| 50 if (milliseconds < 0) { | 51 if (milliseconds < 0) { |
| 51 throw new ArgumentError("sleep: duration cannot be negative"); | 52 throw new ArgumentError("sleep: duration cannot be negative"); |
| 52 } | 53 } |
| 53 _ProcessUtils._sleep(milliseconds); | 54 _ProcessUtils._sleep(milliseconds); |
| 54 } | 55 } |
| 55 | 56 |
| 56 /** | 57 /** |
| 58 * Returns the PID if the current process. | |
|
Anders Johnsen
2013/04/17 09:13:06
Move to Process.currentPid static getter?
Søren Gjesse
2013/04/17 10:15:12
I think the top level getter fits with the top lev
| |
| 59 */ | |
| 60 int get pid => _ProcessUtils._pid(null); | |
| 61 | |
| 62 /** | |
| 57 * [Process] is used to start new processes using the static | 63 * [Process] is used to start new processes using the static |
| 58 * [start] and [run] methods. | 64 * [start] and [run] methods. |
| 59 */ | 65 */ |
| 60 abstract class Process { | 66 abstract class Process { |
| 61 /** | 67 /** |
| 62 * Starts a process running the [executable] with the specified | 68 * Starts a process running the [executable] with the specified |
| 63 * [arguments]. Returns a [:Future<Process>:] that completes with a | 69 * [arguments]. Returns a [:Future<Process>:] that completes with a |
| 64 * Process instance when the process has been successfully | 70 * Process instance when the process has been successfully |
| 65 * started. That [Process] object can be used to interact with the | 71 * started. That [Process] object can be used to interact with the |
| 66 * process. If the process cannot be started the returned [Future] | 72 * process. If the process cannot be started the returned [Future] |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 | 117 |
| 112 /** | 118 /** |
| 113 * Returns the standard input stream of the process as an [IOSink]. | 119 * Returns the standard input stream of the process as an [IOSink]. |
| 114 * | 120 * |
| 115 * Throws an [UnsupportedError] if the process is | 121 * Throws an [UnsupportedError] if the process is |
| 116 * non-interactive. | 122 * non-interactive. |
| 117 */ | 123 */ |
| 118 IOSink get stdin; | 124 IOSink get stdin; |
| 119 | 125 |
| 120 /** | 126 /** |
| 127 * Returns the process id of the process. | |
| 128 */ | |
| 129 int get pid; | |
| 130 | |
| 131 /** | |
| 121 * Returns a [:Future:] which completes with the exit code of the process | 132 * Returns a [:Future:] which completes with the exit code of the process |
| 122 * when the process completes. | 133 * when the process completes. |
| 123 * | 134 * |
| 124 * Throws an [UnsupportedError] if the process is | 135 * Throws an [UnsupportedError] if the process is |
| 125 * non-interactive. | 136 * non-interactive. |
| 126 */ | 137 */ |
| 127 Future<int> exitCode; | 138 Future<int> exitCode; |
| 128 | 139 |
| 129 /** | 140 /** |
| 130 * On Windows, [kill] kills the process, ignoring the [signal] | 141 * On Windows, [kill] kills the process, ignoring the [signal] |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 155 | 166 |
| 156 /** | 167 /** |
| 157 * Standard output from the process as a string. | 168 * Standard output from the process as a string. |
| 158 */ | 169 */ |
| 159 String get stdout; | 170 String get stdout; |
| 160 | 171 |
| 161 /** | 172 /** |
| 162 * Standard error from the process as a string. | 173 * Standard error from the process as a string. |
| 163 */ | 174 */ |
| 164 String get stderr; | 175 String get stderr; |
| 176 | |
| 177 /** | |
| 178 * Process id from the process. | |
| 179 */ | |
| 180 int get pid; | |
| 165 } | 181 } |
| 166 | 182 |
| 167 | 183 |
| 168 /** | 184 /** |
| 169 * [ProcessOptions] represents the options that can be supplied when | 185 * [ProcessOptions] represents the options that can be supplied when |
| 170 * starting a process. | 186 * starting a process. |
| 171 */ | 187 */ |
| 172 class ProcessOptions { | 188 class ProcessOptions { |
| 173 /** | 189 /** |
| 174 * The working directory from which the process is started. Note | 190 * The working directory from which the process is started. Note |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 /** | 290 /** |
| 275 * Contains the system message for the process exception if any. | 291 * Contains the system message for the process exception if any. |
| 276 */ | 292 */ |
| 277 final String message; | 293 final String message; |
| 278 | 294 |
| 279 /** | 295 /** |
| 280 * Contains the OS error code for the process exception if any. | 296 * Contains the OS error code for the process exception if any. |
| 281 */ | 297 */ |
| 282 final int errorCode; | 298 final int errorCode; |
| 283 } | 299 } |
| OLD | NEW |