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 IllegalArgumentException("int status expected"); | 8 throw new IllegalArgumentException("int status expected"); |
| 9 } | 9 } |
| 10 _exit(status); | 10 _exit(status); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 * | 25 * |
| 26 * When the process has been successfully started [onStart] is | 26 * When the process has been successfully started [onStart] is |
| 27 * called on the returned Process object. If the process fails to | 27 * called on the returned Process object. If the process fails to |
| 28 * start [onError] is called on the returned Process object. | 28 * start [onError] is called on the returned Process object. |
| 29 * | 29 * |
| 30 * No data can be written to the process stdin and the process | 30 * No data can be written to the process stdin and the process |
| 31 * cannot be closed nor killed before [onStart] has been invoked. | 31 * cannot be closed nor killed before [onStart] has been invoked. |
| 32 */ | 32 */ |
| 33 static Process start(String executable, | 33 static Process start(String executable, |
| 34 List<String> arguments, | 34 List<String> arguments, |
| 35 [ProcessOptions options]) { | 35 [ProcessOptions options = null]) { |
|
Søren Gjesse
2012/09/18 09:34:16
Isn't null the default default value for optional
Mads Ager (google)
2012/09/18 10:46:39
Yes, it is redundant. Removed.
| |
| 36 return new _Process.start(executable, arguments, options); | 36 return new _Process.start(executable, arguments, options); |
| 37 } | 37 } |
| 38 | 38 |
| 39 /** | 39 /** |
| 40 * Starts a process and runs it non-interactively to completion. The | 40 * Starts a process and runs it non-interactively to completion. The |
| 41 * process run is [executable] with the specified [arguments]. | 41 * process run is [executable] with the specified [arguments]. |
| 42 * | 42 * |
| 43 * An optional [ProcessOptions] object can be passed to specify | 43 * An optional [ProcessOptions] object can be passed to specify |
| 44 * options other than the executable and the arguments. | 44 * options other than the executable and the arguments. |
|
Søren Gjesse
2012/09/18 09:34:16
Maybe add these two lines on the options argument
Mads Ager (google)
2012/09/18 10:46:39
It is actually there already. The comment is just
| |
| 45 * | 45 * |
| 46 * Returns a [:Future<ProcessResult>:] that completes with the | 46 * Returns a [:Future<ProcessResult>:] that completes with the |
| 47 * result of running the process, i.e., exit code, standard out and | 47 * result of running the process, i.e., exit code, standard out and |
| 48 * standard in. | 48 * standard in. |
| 49 */ | 49 */ |
| 50 static Future<ProcessResult> run(String executable, | 50 static Future<ProcessResult> run(String executable, |
| 51 List<String> arguments, | 51 List<String> arguments, |
| 52 [ProcessOptions options]) { | 52 [ProcessOptions options = null]) { |
|
Søren Gjesse
2012/09/18 09:34:16
"= null" needed?
Mads Ager (google)
2012/09/18 10:46:39
Done.
| |
| 53 return _Process.run(executable, arguments, options); | 53 return _Process.run(executable, arguments, options); |
| 54 } | 54 } |
| 55 | 55 |
| 56 /** | 56 /** |
| 57 * Returns an input stream of the process stdout. | 57 * Returns an input stream of the process stdout. |
| 58 * | 58 * |
| 59 * Throws an [UnsupportedOperationException] if the process is | 59 * Throws an [UnsupportedOperationException] if the process is |
| 60 * non-interactive. | 60 * non-interactive. |
| 61 */ | 61 */ |
| 62 abstract InputStream get stdout; | 62 abstract InputStream get stdout; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 | 94 |
| 95 /** | 95 /** |
| 96 * Set an error handler which gets invoked if an operation on the process | 96 * Set an error handler which gets invoked if an operation on the process |
| 97 * fails. | 97 * fails. |
| 98 */ | 98 */ |
| 99 abstract void set onError(void callback(e)); | 99 abstract void set onError(void callback(e)); |
| 100 | 100 |
| 101 /** | 101 /** |
| 102 * On Windows, [kill] kills the process, ignoring the [signal] flag. On | 102 * On Windows, [kill] kills the process, ignoring the [signal] flag. On |
| 103 * Posix systems, [kill] sends [signal] to the process. Depending on the | 103 * Posix systems, [kill] sends [signal] to the process. Depending on the |
| 104 * signal giving, it'll have different meanings. The default [signal] to | 104 * signal giving, it'll have different meanings. The default [signal] to |
|
Søren Gjesse
2012/09/18 09:34:16
No need for documentation of the default value.
Mads Ager (google)
2012/09/18 10:46:39
Done.
| |
| 105 * send is [:ProcessSignal.SIGTERM:]. When the process terminates as a result | 105 * send is [:ProcessSignal.SIGTERM:]. When the process terminates as a result |
| 106 * of calling [kill] [onExit] is called. If the kill operation fails, | 106 * of calling [kill] [onExit] is called. If the kill operation fails, |
| 107 * [onError] is called. | 107 * [onError] is called. |
| 108 */ | 108 */ |
| 109 abstract void kill([ProcessSignal signal]); | 109 abstract void kill([ProcessSignal signal = ProcessSignal.SIGTERM]); |
| 110 | 110 |
| 111 /** | 111 /** |
| 112 * Terminates the streams of a process. [close] must be called on a | 112 * 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 | 113 * process to free the system resources associated with it if not all |
| 114 * data on the stdout and stderr streams have been read. Usually, | 114 * 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 | 115 * 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. | 116 * 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] | 117 * Once a process has been closed it can no longer be killed and [onExit] |
| 118 * is detached so the application is not notified of process termination. | 118 * is detached so the application is not notified of process termination. |
| 119 */ | 119 */ |
| 120 abstract void close(); | 120 abstract void close(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 | 123 |
| 124 /** | 124 /** |
| 125 * [ProcessResult] represents the result of running a non-interactive | 125 * [ProcessResult] represents the result of running a non-interactive |
| 126 * process started with [:Process.run:]. | 126 * process started with [:Process.run:]. |
| 127 */ | 127 */ |
| 128 interface ProcessResult { | 128 abstract class ProcessResult { |
| 129 /** | 129 /** |
| 130 * Exit code for the process. | 130 * Exit code for the process. |
| 131 */ | 131 */ |
| 132 int get exitCode; | 132 int get exitCode; |
| 133 | 133 |
| 134 /** | 134 /** |
| 135 * Standard output from the process as a string. | 135 * Standard output from the process as a string. |
| 136 */ | 136 */ |
| 137 String get stdout; | 137 String get stdout; |
| 138 | 138 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 static const ProcessSignal SIGPROF = const ProcessSignal._signal(27); | 222 static const ProcessSignal SIGPROF = const ProcessSignal._signal(27); |
| 223 static const ProcessSignal SIGPOLL = const ProcessSignal._signal(29); | 223 static const ProcessSignal SIGPOLL = const ProcessSignal._signal(29); |
| 224 static const ProcessSignal SIGSYS = const ProcessSignal._signal(31); | 224 static const ProcessSignal SIGSYS = const ProcessSignal._signal(31); |
| 225 | 225 |
| 226 const ProcessSignal._signal(int this._signalNumber); | 226 const ProcessSignal._signal(int this._signalNumber); |
| 227 final int _signalNumber; | 227 final int _signalNumber; |
| 228 } | 228 } |
| 229 | 229 |
| 230 | 230 |
| 231 class ProcessException implements Exception { | 231 class ProcessException implements Exception { |
| 232 const ProcessException([String this.message, int this.errorCode = 0]); | 232 const ProcessException([String this.message = "", int this.errorCode = 0]); |
| 233 String toString() => "ProcessException: $message ($errorCode)"; | 233 String toString() => "ProcessException: $message ($errorCode)"; |
| 234 | 234 |
| 235 /** | 235 /** |
| 236 * Contains the system message for the process exception if any. | 236 * Contains the system message for the process exception if any. |
| 237 */ | 237 */ |
| 238 final String message; | 238 final String message; |
| 239 | 239 |
| 240 /** | 240 /** |
| 241 * Contains the OS error code for the process exception if any. | 241 * Contains the OS error code for the process exception if any. |
| 242 */ | 242 */ |
| 243 final int errorCode; | 243 final int errorCode; |
| 244 } | 244 } |
| OLD | NEW |