| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 interface Process default _Process { | 5 interface Process default _Process { |
| 6 /* | 6 /** |
| 7 * Creates a new process object preparing to run the executable | 7 * Creates a new process object and starts a process running the executable |
| 8 * found at [path] with the specified [arguments]. | 8 * found at [path] with the specified [arguments]. When the process has |
| 9 * been successfully started the [startHandler] is called. If the process |
| 10 * fails to start the [errorHandler] is called. |
| 11 * |
| 12 * No data can be written to the process stdin and the process cannot be |
| 13 * closed nor killed before the [startHandler] has been invoked. |
| 9 */ | 14 */ |
| 10 Process(String path, List<String> arguments); | 15 Process.start(String path, List<String> arguments); |
| 11 | 16 |
| 12 /* | 17 /** |
| 13 * Start the process by running the specified executable. An | |
| 14 * exception of type [ProcessException] is thrown if the process | |
| 15 * cannot be started. There is a remote possibility of an exception | |
| 16 * being thrown even though the child process did actually start. | |
| 17 */ | |
| 18 void start(); | |
| 19 | |
| 20 /* | |
| 21 * Returns an input stream of the process stdout. | 18 * Returns an input stream of the process stdout. |
| 22 */ | 19 */ |
| 23 InputStream get stdout(); | 20 InputStream get stdout(); |
| 24 | 21 |
| 25 /* | 22 /** |
| 26 * Returns an input stream of the process stderr. | 23 * Returns an input stream of the process stderr. |
| 27 */ | 24 */ |
| 28 InputStream get stderr(); | 25 InputStream get stderr(); |
| 29 | 26 |
| 30 /* | 27 /** |
| 31 * Returns an output stream to the process stdin. | 28 * Returns an output stream to the process stdin. |
| 32 */ | 29 */ |
| 33 OutputStream get stdin(); | 30 OutputStream get stdin(); |
| 34 | 31 |
| 35 /* | 32 /** |
| 33 * Set the start handler which gets invoked when the process is |
| 34 * successfully started. |
| 35 */ |
| 36 void set startHandler(void callback()); |
| 37 |
| 38 /** |
| 36 * Sets an exit handler which gets invoked when the process terminates. | 39 * Sets an exit handler which gets invoked when the process terminates. |
| 37 */ | 40 */ |
| 38 void set exitHandler(void callback(int exitCode)); | 41 void set exitHandler(void callback(int exitCode)); |
| 39 | 42 |
| 40 /* | 43 /** |
| 41 * Kills the process with [signal]. | 44 * Set an error handler which gets invoked if an operation on the process |
| 45 * fails. |
| 42 */ | 46 */ |
| 43 bool kill(); | 47 void set errorHandler(void callback(ProcessException error)); |
| 44 | 48 |
| 45 /* | 49 /** |
| 46 * Terminates the streams and closes the exit handler of a process. | 50 * Kills the process. When the process terminates as a result of calling |
| 51 * [kill] the [exitHandler] is called. If the kill operation fails, the |
| 52 * [errorHandler] is called. |
| 53 */ |
| 54 void kill(); |
| 55 |
| 56 /** |
| 57 * Terminates the streams of a process. [close] most be called on a process |
| 58 * to free the system resources associated with it. Usually, close should be |
| 59 * called in the [exitHandler]. Once a process has been closed it can no |
| 60 * longer be killed and the [exitHandler] is detached so the application is |
| 61 * not notified of process termination. |
| 47 */ | 62 */ |
| 48 void close(); | 63 void close(); |
| 49 } | 64 } |
| 50 | 65 |
| 51 | 66 |
| 52 class ProcessException implements Exception { | 67 class ProcessException implements Exception { |
| 53 const ProcessException([String this.message, int this.errorCode = 0]); | 68 const ProcessException([String this.message, int this.errorCode = 0]); |
| 54 String toString() => "ProcessException: $message"; | 69 String toString() => "ProcessException: $message"; |
| 55 | 70 |
| 56 /* | 71 /** |
| 57 * Contains the system message for the process exception if any. | 72 * Contains the system message for the process exception if any. |
| 58 */ | 73 */ |
| 59 final String message; | 74 final String message; |
| 60 | 75 |
| 61 /* | 76 /** |
| 62 * Contains the OS error code for the process exception if any. | 77 * Contains the OS error code for the process exception if any. |
| 63 */ | 78 */ |
| 64 final int errorCode; | 79 final int errorCode; |
| 65 } | 80 } |
| OLD | NEW |