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 /** | 5 /** |
6 * [Process] objects are used to start new processes and interact with | 6 * [Process] objects are used to start new processes and interact with |
7 * them. | 7 * them. |
8 */ | 8 */ |
9 interface Process default _Process { | 9 interface Process default _Process { |
10 /** | 10 /** |
11 * Creates a new process object and starts a process running the | 11 * Creates a new process object and starts a process running the |
12 * [executable] with the specified [arguments]. When the process has been | 12 * [executable] with the specified [arguments]. When the process has |
13 * successfully started the [startHandler] is called. If the process fails | 13 * been successfully started [onStart] is called. If the process |
14 * to start the [errorHandler] is called. | 14 * fails to start [onError] is called. |
15 * | 15 * |
16 * An optional [workingDirectory] can be passed to specify where the process | 16 * An optional [workingDirectory] can be passed to specify where the process |
17 * is run from. Note that the change of directory occurs before executing | 17 * is run from. Note that the change of directory occurs before executing |
18 * the process on some platforms, which may have impact when using relative | 18 * the process on some platforms, which may have impact when using relative |
19 * paths for [executable] and [arguments]. | 19 * paths for [executable] and [arguments]. |
20 * | 20 * |
21 * No data can be written to the process stdin and the process cannot be | 21 * No data can be written to the process stdin and the process |
22 * closed nor killed before the [startHandler] has been invoked. | 22 * cannot be closed nor killed before [onStart] has been invoked. |
23 */ | 23 */ |
24 Process.start(String executable, | 24 Process.start(String executable, |
25 List<String> arguments, | 25 List<String> arguments, |
26 [String workingDirectory]); | 26 [String workingDirectory]); |
27 | 27 |
28 /** | 28 /** |
29 * Returns an input stream of the process stdout. | 29 * Returns an input stream of the process stdout. |
30 */ | 30 */ |
31 InputStream get stdout(); | 31 InputStream get stdout(); |
32 | 32 |
33 /** | 33 /** |
34 * Returns an input stream of the process stderr. | 34 * Returns an input stream of the process stderr. |
35 */ | 35 */ |
36 InputStream get stderr(); | 36 InputStream get stderr(); |
37 | 37 |
38 /** | 38 /** |
39 * Returns an output stream to the process stdin. | 39 * Returns an output stream to the process stdin. |
40 */ | 40 */ |
41 OutputStream get stdin(); | 41 OutputStream get stdin(); |
42 | 42 |
43 /** | 43 /** |
44 * Set the start handler which gets invoked when the process is | 44 * Set the start handler which gets invoked when the process is |
45 * successfully started. | 45 * successfully started. |
46 */ | 46 */ |
47 void set startHandler(void callback()); | 47 void set onStart(void callback()); |
48 | 48 |
49 /** | 49 /** |
50 * Sets an exit handler which gets invoked when the process terminates. | 50 * Sets an exit handler which gets invoked when the process terminates. |
51 */ | 51 */ |
52 void set exitHandler(void callback(int exitCode)); | 52 void set onExit(void callback(int exitCode)); |
53 | 53 |
54 /** | 54 /** |
55 * Set an error handler which gets invoked if an operation on the process | 55 * Set an error handler which gets invoked if an operation on the process |
56 * fails. | 56 * fails. |
57 */ | 57 */ |
58 void set errorHandler(void callback(ProcessException error)); | 58 void set onError(void callback(ProcessException error)); |
59 | 59 |
60 /** | 60 /** |
61 * Kills the process. When the process terminates as a result of calling | 61 * Kills the process. When the process terminates as a result of |
62 * [kill] the [exitHandler] is called. If the kill operation fails, the | 62 * calling [kill] [onExit] is called. If the kill operation fails, |
63 * [errorHandler] is called. | 63 * [onError] is called. |
64 */ | 64 */ |
65 void kill(); | 65 void kill(); |
66 | 66 |
67 /** | 67 /** |
68 * Terminates the streams of a process. [close] most be called on a process | 68 * Terminates the streams of a process. [close] most be called on a |
69 * to free the system resources associated with it. Usually, close should be | 69 * process to free the system resources associated with it. Usually, |
70 * called in the [exitHandler]. Once a process has been closed it can no | 70 * close should be called in [onExit]. Once a process has been |
71 * longer be killed and the [exitHandler] is detached so the application is | 71 * closed it can no longer be killed and [onExit] is detached so the |
72 * not notified of process termination. | 72 * application is not notified of process termination. |
73 */ | 73 */ |
74 void close(); | 74 void close(); |
75 } | 75 } |
76 | 76 |
77 | 77 |
78 class ProcessException implements Exception { | 78 class ProcessException implements Exception { |
79 const ProcessException([String this.message, int this.errorCode = 0]); | 79 const ProcessException([String this.message, int this.errorCode = 0]); |
80 String toString() => "ProcessException: $message"; | 80 String toString() => "ProcessException: $message"; |
81 | 81 |
82 /** | 82 /** |
83 * Contains the system message for the process exception if any. | 83 * Contains the system message for the process exception if any. |
84 */ | 84 */ |
85 final String message; | 85 final String message; |
86 | 86 |
87 /** | 87 /** |
88 * Contains the OS error code for the process exception if any. | 88 * Contains the OS error code for the process exception if any. |
89 */ | 89 */ |
90 final int errorCode; | 90 final int errorCode; |
91 } | 91 } |
OLD | NEW |