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 class _ProcessUtils { | |
|
Søren Gjesse
2012/10/30 09:28:32
TODO?
Mads Ager (google)
2012/10/30 11:12:40
Done.
| |
| 6 external static _exit(int status); | |
| 7 } | |
| 8 | |
| 5 /** Exit the Dart VM process with the given [status] code. */ | 9 /** Exit the Dart VM process with the given [status] code. */ |
| 6 void exit(int status) { | 10 void exit(int status) { |
| 7 if (status is !int) { | 11 if (status is !int) { |
| 8 throw new ArgumentError("int status expected"); | 12 throw new ArgumentError("int status expected"); |
| 9 } | 13 } |
| 10 _exit(status); | 14 _ProcessUtils._exit(status); |
| 11 } | 15 } |
| 12 | 16 |
| 13 /** | 17 /** |
| 14 * [Process] is used to start new processes using the static | 18 * [Process] is used to start new processes using the static |
| 15 * [start] and [run] methods. | 19 * [start] and [run] methods. |
| 16 */ | 20 */ |
| 17 class Process { | 21 abstract class Process { |
| 18 /** | 22 /** |
| 19 * Starts a process running the [executable] with the specified | 23 * Starts a process running the [executable] with the specified |
| 20 * [arguments]. Returns a [:Future<Process>:] that completes with a | 24 * [arguments]. Returns a [:Future<Process>:] that completes with a |
| 21 * Process instance when the process has been successfully | 25 * Process instance when the process has been successfully |
| 22 * started. That [Process] object can be used to interact with the | 26 * started. That [Process] object can be used to interact with the |
| 23 * process. If the process cannot be started the returned [Future] | 27 * process. If the process cannot be started the returned [Future] |
| 24 * completes with an exception. | 28 * completes with an exception. |
| 25 * | 29 * |
| 26 * An optional [ProcessOptions] object can be passed to specify | 30 * An optional [ProcessOptions] object can be passed to specify |
| 27 * options other than the executable and the arguments. | 31 * options other than the executable and the arguments. |
| 28 * | 32 * |
| 29 * Users must read all data coming on the [stdout] and [stderr] | 33 * Users must read all data coming on the [stdout] and [stderr] |
| 30 * streams of processes started with [:Process.start:]. If the user | 34 * streams of processes started with [:Process.start:]. If the user |
| 31 * does not read all data on the streams the underlying system | 35 * does not read all data on the streams the underlying system |
| 32 * resources will not be freed since there is still pending data. | 36 * resources will not be freed since there is still pending data. |
| 33 */ | 37 */ |
| 34 static Future<Process> start(String executable, | 38 external static Future<Process> start(String executable, |
| 35 List<String> arguments, | 39 List<String> arguments, |
| 36 [ProcessOptions options]) { | 40 [ProcessOptions options]); |
| 37 return _Process.start(executable, arguments, options); | |
| 38 } | |
| 39 | 41 |
| 40 /** | 42 /** |
| 41 * Starts a process and runs it non-interactively to completion. The | 43 * Starts a process and runs it non-interactively to completion. The |
| 42 * process run is [executable] with the specified [arguments]. | 44 * process run is [executable] with the specified [arguments]. |
| 43 * | 45 * |
| 44 * An optional [ProcessOptions] object can be passed to specify | 46 * An optional [ProcessOptions] object can be passed to specify |
| 45 * options other than the executable and the arguments. | 47 * options other than the executable and the arguments. |
| 46 * | 48 * |
| 47 * Returns a [:Future<ProcessResult>:] that completes with the | 49 * Returns a [:Future<ProcessResult>:] that completes with the |
| 48 * result of running the process, i.e., exit code, standard out and | 50 * result of running the process, i.e., exit code, standard out and |
| 49 * standard in. | 51 * standard in. |
| 50 */ | 52 */ |
| 51 static Future<ProcessResult> run(String executable, | 53 external static Future<ProcessResult> run(String executable, |
| 52 List<String> arguments, | 54 List<String> arguments, |
| 53 [ProcessOptions options]) { | 55 [ProcessOptions options]); |
| 54 return _Process.run(executable, arguments, options); | |
| 55 } | |
| 56 | 56 |
| 57 /** | 57 /** |
| 58 * Returns an input stream of the process stdout. | 58 * Returns an input stream of the process stdout. |
| 59 * | 59 * |
| 60 * Throws an [UnsupportedError] if the process is | 60 * Throws an [UnsupportedError] if the process is |
| 61 * non-interactive. | 61 * non-interactive. |
| 62 */ | 62 */ |
| 63 abstract InputStream get stdout; | 63 InputStream get stdout; |
| 64 | 64 |
| 65 /** | 65 /** |
| 66 * Returns an input stream of the process stderr. | 66 * Returns an input stream of the process stderr. |
| 67 * | 67 * |
| 68 * Throws an [UnsupportedError] if the process is | 68 * Throws an [UnsupportedError] if the process is |
| 69 * non-interactive. | 69 * non-interactive. |
| 70 */ | 70 */ |
| 71 abstract InputStream get stderr; | 71 InputStream get stderr; |
| 72 | 72 |
| 73 /** | 73 /** |
| 74 * Returns an output stream to the process stdin. | 74 * Returns an output stream to the process stdin. |
| 75 * | 75 * |
| 76 * Throws an [UnsupportedError] if the process is | 76 * Throws an [UnsupportedError] if the process is |
| 77 * non-interactive. | 77 * non-interactive. |
| 78 */ | 78 */ |
| 79 abstract OutputStream get stdin; | 79 OutputStream get stdin; |
| 80 | 80 |
| 81 /** | 81 /** |
| 82 * Sets an exit handler which gets invoked when the process | 82 * Sets an exit handler which gets invoked when the process |
| 83 * terminates. | 83 * terminates. |
| 84 * | 84 * |
| 85 * Throws an [UnsupportedError] if the process is | 85 * Throws an [UnsupportedError] if the process is |
| 86 * non-interactive. | 86 * non-interactive. |
| 87 */ | 87 */ |
| 88 abstract void set onExit(void callback(int exitCode)); | 88 void set onExit(void callback(int exitCode)); |
| 89 | 89 |
| 90 /** | 90 /** |
| 91 * On Windows, [kill] kills the process, ignoring the [signal] | 91 * On Windows, [kill] kills the process, ignoring the [signal] |
| 92 * flag. On Posix systems, [kill] sends [signal] to the | 92 * flag. On Posix systems, [kill] sends [signal] to the |
| 93 * process. Depending on the signal giving, it'll have different | 93 * process. Depending on the signal giving, it'll have different |
| 94 * meanings. When the process terminates as a result of calling | 94 * meanings. When the process terminates as a result of calling |
| 95 * [kill] [onExit] is called. | 95 * [kill] [onExit] is called. |
| 96 * | 96 * |
| 97 * Returns [:true:] if the process is successfully killed (the | 97 * Returns [:true:] if the process is successfully killed (the |
| 98 * signal is successfully sent). Returns [:false:] if the process | 98 * signal is successfully sent). Returns [:false:] if the process |
| 99 * could not be killed (the signal could not be sent). Usually, | 99 * could not be killed (the signal could not be sent). Usually, |
| 100 * a [:false:] return value from kill means that the process is | 100 * a [:false:] return value from kill means that the process is |
| 101 * already dead. | 101 * already dead. |
| 102 */ | 102 */ |
| 103 abstract bool kill([ProcessSignal signal = ProcessSignal.SIGTERM]); | 103 bool kill([ProcessSignal signal = ProcessSignal.SIGTERM]); |
| 104 } | 104 } |
| 105 | 105 |
| 106 | 106 |
| 107 /** | 107 /** |
| 108 * [ProcessResult] represents the result of running a non-interactive | 108 * [ProcessResult] represents the result of running a non-interactive |
| 109 * process started with [:Process.run:]. | 109 * process started with [:Process.run:]. |
| 110 */ | 110 */ |
| 111 abstract class ProcessResult { | 111 abstract class ProcessResult { |
| 112 /** | 112 /** |
| 113 * Exit code for the process. | 113 * Exit code for the process. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 /** | 218 /** |
| 219 * Contains the system message for the process exception if any. | 219 * Contains the system message for the process exception if any. |
| 220 */ | 220 */ |
| 221 final String message; | 221 final String message; |
| 222 | 222 |
| 223 /** | 223 /** |
| 224 * Contains the OS error code for the process exception if any. | 224 * Contains the OS error code for the process exception if any. |
| 225 */ | 225 */ |
| 226 final int errorCode; | 226 final int errorCode; |
| 227 } | 227 } |
| OLD | NEW |