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