| 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)); |
| 94 | 84 |
| 95 /** | 85 /** |
| 96 * Set an error handler which gets invoked if an operation on the process | |
| 97 * fails. | |
| 98 */ | |
| 99 abstract void set onError(void callback(e)); | |
| 100 | |
| 101 /** | |
| 102 * On Windows, [kill] kills the process, ignoring the [signal] | 86 * On Windows, [kill] kills the process, ignoring the [signal] |
| 103 * flag. On Posix systems, [kill] sends [signal] to the | 87 * flag. On Posix systems, [kill] sends [signal] to the |
| 104 * process. Depending on the signal giving, it'll have different | 88 * process. Depending on the signal giving, it'll have different |
| 105 * meanings. When the process terminates as a result of calling | 89 * meanings. When the process terminates as a result of calling |
| 106 * [kill] [onExit] is called. If the kill operation fails, [onError] | 90 * [kill] [onExit] is called. If the kill operation fails an |
| 107 * is called. | 91 * exception is thrown. |
| 108 */ | 92 */ |
| 109 abstract void kill([ProcessSignal signal = ProcessSignal.SIGTERM]); | 93 abstract void kill([ProcessSignal signal = ProcessSignal.SIGTERM]); |
| 110 | 94 |
| 111 /** | 95 /** |
| 112 * Terminates the streams of a process. [close] must be called on a | 96 * Terminates the streams of a process. [close] must be called on a |
| 113 * process to free the system resources associated with it if not all | 97 * process to free the system resources associated with it if not all |
| 114 * data on the stdout and stderr streams have been read. Usually, | 98 * data on the stdout and stderr streams have been read. Usually, |
| 115 * close should be called in [onExit], but care must be taken to actually | 99 * close should be called in [onExit], but care must be taken to actually |
| 116 * wait on the stderr and stdout streams to close if all data is required. | 100 * wait on the stderr and stdout streams to close if all data is required. |
| 117 * Once a process has been closed it can no longer be killed and [onExit] | 101 * Once a process has been closed it can no longer be killed and [onExit] |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 /** | 219 /** |
| 236 * Contains the system message for the process exception if any. | 220 * Contains the system message for the process exception if any. |
| 237 */ | 221 */ |
| 238 final String message; | 222 final String message; |
| 239 | 223 |
| 240 /** | 224 /** |
| 241 * Contains the OS error code for the process exception if any. | 225 * Contains the OS error code for the process exception if any. |
| 242 */ | 226 */ |
| 243 final int errorCode; | 227 final int errorCode; |
| 244 } | 228 } |
| OLD | NEW |