Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 void _exit(int status); | 10 external static void _exit(int status); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 } | 93 } |
| 94 _ProcessUtils._sleep(milliseconds); | 94 _ProcessUtils._sleep(milliseconds); |
| 95 } | 95 } |
| 96 | 96 |
| 97 /** | 97 /** |
| 98 * Returns the PID of the current process. | 98 * Returns the PID of the current process. |
| 99 */ | 99 */ |
| 100 int get pid => _ProcessUtils._pid(null); | 100 int get pid => _ProcessUtils._pid(null); |
| 101 | 101 |
| 102 /** | 102 /** |
| 103 * Modes for running a new process. | |
| 104 */ | |
| 105 enum ProcessStartMode { | |
| 106 /// Normal child process. | |
| 107 NORMAL, | |
| 108 /// Detached child process. | |
| 109 DETACHED, | |
| 110 /// Detachad clild process with stdin, stdout and stderr connected. | |
|
Lasse Reichstein Nielsen
2015/01/30 12:11:37
clild -> child
Connected to what?
Søren Gjesse
2015/02/02 13:56:44
Done.
| |
| 111 DETACHED_WITH_STDIO | |
| 112 } | |
| 113 | |
| 114 /** | |
| 103 * The means to execute a program. | 115 * The means to execute a program. |
| 104 * | 116 * |
| 105 * Use the static [start] and [run] methods to start a new process. | 117 * Use the static [start] and [run] methods to start a new process. |
| 106 * The run method executes the process non-interactively to completion. | 118 * The run method executes the process non-interactively to completion. |
| 107 * In contrast, the start method allows your code to interact with the | 119 * In contrast, the start method allows your code to interact with the |
| 108 * running process. | 120 * running process. |
| 109 * | 121 * |
| 110 * ## Start a process with the run method | 122 * ## Start a process with the run method |
| 111 * | 123 * |
| 112 * The following code sample uses the run method to create a process | 124 * The following code sample uses the run method to create a process |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 * include the parent process's environment, with [environment] taking | 253 * include the parent process's environment, with [environment] taking |
| 242 * precedence. Default is `true`. | 254 * precedence. Default is `true`. |
| 243 * | 255 * |
| 244 * If [runInShell] is `true`, the process will be spawned through a system | 256 * If [runInShell] is `true`, the process will be spawned through a system |
| 245 * shell. On Linux and Mac OS, [:/bin/sh:] is used, while | 257 * shell. On Linux and Mac OS, [:/bin/sh:] is used, while |
| 246 * [:%WINDIR%\system32\cmd.exe:] is used on Windows. | 258 * [:%WINDIR%\system32\cmd.exe:] is used on Windows. |
| 247 * | 259 * |
| 248 * Users must read all data coming on the [stdout] and [stderr] | 260 * Users must read all data coming on the [stdout] and [stderr] |
| 249 * streams of processes started with [:Process.start:]. If the user | 261 * streams of processes started with [:Process.start:]. If the user |
| 250 * does not read all data on the streams the underlying system | 262 * does not read all data on the streams the underlying system |
| 251 * resources will not be freed since there is still pending data. | 263 * resources will not be freed since there is still pending data. |
|
Lasse Reichstein Nielsen
2015/01/30 12:11:37
freed -> released
Søren Gjesse
2015/02/02 13:56:44
Done.
| |
| 252 * | 264 * |
| 253 * The following code uses `Process.start` to grep for `main` in the | 265 * The following code uses `Process.start` to grep for `main` in the |
| 254 * file `test.dart` on Linux. | 266 * file `test.dart` on Linux. |
| 255 * | 267 * |
| 256 * Process.start('grep', ['-i', 'main', 'test.dart']).then((process) { | 268 * Process.start('grep', ['-i', 'main', 'test.dart']).then((process) { |
| 257 * stdout.addStream(process.stdout); | 269 * stdout.addStream(process.stdout); |
| 258 * stderr.addStream(process.stderr); | 270 * stderr.addStream(process.stderr); |
| 259 * }); | 271 * }); |
| 260 * | 272 * |
| 261 * If [detach] is `true` a detached process will be created. A | 273 * If [mode] is [ProcessStartMode.NORMAL] a normal child process |
| 262 * detached process has no connection to its parent, and can | 274 * will be started. |
|
Lasse Reichstein Nielsen
2015/01/30 12:11:37
Explain what "normal" means, or rephrase as:
If [
Søren Gjesse
2015/02/02 13:56:44
Done.
| |
| 263 * keep running on its own when the parent dies. The only | 275 * |
| 276 * If `mode` is [ProcessStartMode.DETACHED] a detached process will | |
| 277 * be created. A detached process has no connection to its parent, | |
| 278 * and can keep running on its own when the parent dies. The only | |
| 264 * information available from a detached process is its `pid`. There | 279 * information available from a detached process is its `pid`. There |
| 265 * is no connection to its `stdin`, `stdout` or `stderr` nor will its | 280 * is no connection to its `stdin`, `stdout` or `stderr` nor will |
|
Lasse Reichstein Nielsen
2015/01/30 12:11:37
comma before "nor"?
Søren Gjesse
2015/02/02 13:56:44
Done.
| |
| 266 * exit code become available when it terminates. | 281 * its exit code become available when it terminates. |
| 282 * | |
| 283 * If `mode` is [ProcessStartMode.DETACHED_WITH_STDIO] a detached | |
| 284 * process will be created where the `stdin`, `stdout` and `stderr` | |
| 285 * are connected. The creator can communication with the child. When | |
|
Lasse Reichstein Nielsen
2015/01/30 12:11:37
can communication with the child ->
can communica
Søren Gjesse
2015/02/02 13:56:44
Done.
| |
| 286 * these communication channels are closed the detached process will | |
|
Lasse Reichstein Nielsen
2015/01/30 12:11:37
Rewrite as: The detached process will keep running
Søren Gjesse
2015/02/02 13:56:44
Done.
| |
| 287 * keep running. Its exit code will not become available when it | |
|
Lasse Reichstein Nielsen
2015/01/30 12:11:37
Its -> The process'
Søren Gjesse
2015/02/02 13:56:44
Done.
| |
| 288 * terminated. | |
|
Lasse Reichstein Nielsen
2015/01/30 12:11:37
terminated -> terminates.
Søren Gjesse
2015/02/02 13:56:44
Done.
| |
| 289 * | |
| 290 * The default value for `mode` is `ProcessStartMode.NORMAL`. | |
| 267 */ | 291 */ |
| 268 external static Future<Process> start( | 292 external static Future<Process> start( |
| 269 String executable, | 293 String executable, |
| 270 List<String> arguments, | 294 List<String> arguments, |
| 271 {String workingDirectory, | 295 {String workingDirectory, |
| 272 Map<String, String> environment, | 296 Map<String, String> environment, |
| 273 bool includeParentEnvironment: true, | 297 bool includeParentEnvironment: true, |
| 274 bool runInShell: false, | 298 bool runInShell: false, |
| 275 bool detach: false}); | 299 ProcessStartMode mode: ProcessStartMode.NORMAL}); |
| 276 | 300 |
| 277 /** | 301 /** |
| 278 * Starts a process and runs it non-interactively to completion. The | 302 * Starts a process and runs it non-interactively to completion. The |
| 279 * process run is [executable] with the specified [arguments]. | 303 * process run is [executable] with the specified [arguments]. |
| 280 * | 304 * |
| 281 * Use [workingDirectory] to set the working directory for the process. Note | 305 * Use [workingDirectory] to set the working directory for the process. Note |
| 282 * that the change of directory occurs before executing the process on some | 306 * that the change of directory occurs before executing the process on some |
| 283 * platforms, which may have impact when using relative paths for the | 307 * platforms, which may have impact when using relative paths for the |
| 284 * executable and the arguments. | 308 * executable and the arguments. |
| 285 * | 309 * |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 521 final int errorCode; | 545 final int errorCode; |
| 522 | 546 |
| 523 const ProcessException(this.executable, this.arguments, [this.message = "", | 547 const ProcessException(this.executable, this.arguments, [this.message = "", |
| 524 this.errorCode = 0]); | 548 this.errorCode = 0]); |
| 525 String toString() { | 549 String toString() { |
| 526 var msg = (message == null) ? 'OS error code: $errorCode' : message; | 550 var msg = (message == null) ? 'OS error code: $errorCode' : message; |
| 527 var args = arguments.join(' '); | 551 var args = arguments.join(' '); |
| 528 return "ProcessException: $msg\n Command: $executable $args"; | 552 return "ProcessException: $msg\n Command: $executable $args"; |
| 529 } | 553 } |
| 530 } | 554 } |
| OLD | NEW |