Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** Exit the Dart VM process with the given [status] code. */ | 5 /** Exit the Dart VM process with the given [status] code. */ |
| 6 void exit(int status) { | 6 void exit(int status) { |
| 7 if (status is !int) { | 7 if (status is !int) { |
| 8 throw new ArgumentError("int status expected"); | 8 throw new ArgumentError("int status expected"); |
| 9 } | 9 } |
| 10 _exit(status); | 10 _exit(status); |
| 11 } | 11 } |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * [Process] is used to start new processes using the static | 14 * [Process] is used to start new processes using the static |
| 15 * [start] and [run] methods. | 15 * [start] and [run] methods. |
| 16 */ | 16 */ |
| 17 class Process { | 17 class Process { |
| 18 /** | 18 /** |
| 19 * Starts a process running the [executable] with the specified | 19 * Starts a process running the [executable] with the specified |
| 20 * [arguments]. Returns a [Process] instance that can be used to | 20 * [arguments]. Returns a [:Future<Process>:] that completes with a |
| 21 * interact with the process. | 21 * Process instance when the process has been successfully |
| 22 * started. That [Process] object can be used to interact with the | |
| 23 * process. If the process cannot be started the returned [Future] | |
| 24 * completes with an exception. | |
| 22 * | 25 * |
| 23 * An optional [ProcessOptions] object can be passed to specify | 26 * An optional [ProcessOptions] object can be passed to specify |
| 24 * options other than the executable and the arguments. | 27 * options other than the executable and the arguments. |
| 25 * | |
| 26 * When the process has been successfully started [onStart] is | |
| 27 * called on the returned Process object. If the process fails to | |
| 28 * start [onError] is called on the returned Process object. | |
| 29 * | |
| 30 * No data can be written to the process stdin and the process | |
| 31 * cannot be closed nor killed before [onStart] has been invoked. | |
| 32 */ | 28 */ |
| 33 static Process start(String executable, | 29 static Future<Process> start(String executable, |
| 34 List<String> arguments, | 30 List<String> arguments, |
| 35 [ProcessOptions options]) { | 31 [ProcessOptions options]) { |
| 36 return new _Process.start(executable, arguments, options); | 32 return _Process.start(executable, arguments, options); |
| 37 } | 33 } |
| 38 | 34 |
| 39 /** | 35 /** |
| 40 * Starts a process and runs it non-interactively to completion. The | 36 * Starts a process and runs it non-interactively to completion. The |
| 41 * process run is [executable] with the specified [arguments]. | 37 * process run is [executable] with the specified [arguments]. |
| 42 * | 38 * |
| 43 * An optional [ProcessOptions] object can be passed to specify | 39 * An optional [ProcessOptions] object can be passed to specify |
| 44 * options other than the executable and the arguments. | 40 * options other than the executable and the arguments. |
| 45 * | 41 * |
| 46 * Returns a [:Future<ProcessResult>:] that completes with the | 42 * Returns a [:Future<ProcessResult>:] that completes with the |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 71 | 67 |
| 72 /** | 68 /** |
| 73 * Returns an output stream to the process stdin. | 69 * Returns an output stream to the process stdin. |
| 74 * | 70 * |
| 75 * Throws an [UnsupportedOperationException] if the process is | 71 * Throws an [UnsupportedOperationException] if the process is |
| 76 * non-interactive. | 72 * non-interactive. |
| 77 */ | 73 */ |
| 78 abstract OutputStream get stdin; | 74 abstract OutputStream get stdin; |
| 79 | 75 |
| 80 /** | 76 /** |
| 81 * Set the start handler which gets invoked when the process is | |
| 82 * successfully started. | |
| 83 */ | |
| 84 abstract void set onStart(void callback()); | |
| 85 | |
| 86 /** | |
| 87 * Sets an exit handler which gets invoked when the process | 77 * Sets an exit handler which gets invoked when the process |
| 88 * terminates. | 78 * terminates. |
| 89 * | 79 * |
| 90 * Throws an [UnsupportedOperationException] if the process is | 80 * Throws an [UnsupportedOperationException] if the process is |
| 91 * non-interactive. | 81 * non-interactive. |
| 92 */ | 82 */ |
| 93 abstract void set onExit(void callback(int exitCode)); | 83 abstract void set onExit(void callback(int exitCode)); |
|
Søren Gjesse
2012/10/12 07:47:22
Shouldn't this return a future (with the exit code
Mads Ager (google)
2012/10/12 08:44:46
That could make sense, yes. Let's experiment with
| |
| 94 | 84 |
| 95 /** | 85 /** |
| 96 * Set an error handler which gets invoked if an operation on the process | 86 * Set an error handler which gets invoked if an operation on the process |
| 97 * fails. | 87 * fails. |
| 98 */ | 88 */ |
| 99 abstract void set onError(void callback(e)); | 89 abstract void set onError(void callback(e)); |
| 100 | 90 |
| 101 /** | 91 /** |
| 102 * On Windows, [kill] kills the process, ignoring the [signal] | 92 * On Windows, [kill] kills the process, ignoring the [signal] |
| 103 * flag. On Posix systems, [kill] sends [signal] to the | 93 * flag. On Posix systems, [kill] sends [signal] to the |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 /** | 225 /** |
| 236 * Contains the system message for the process exception if any. | 226 * Contains the system message for the process exception if any. |
| 237 */ | 227 */ |
| 238 final String message; | 228 final String message; |
| 239 | 229 |
| 240 /** | 230 /** |
| 241 * Contains the OS error code for the process exception if any. | 231 * Contains the OS error code for the process exception if any. |
| 242 */ | 232 */ |
| 243 final int errorCode; | 233 final int errorCode; |
| 244 } | 234 } |
| OLD | NEW |