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(int status) native "Exit"; | 5 patch class Process { |
| 6 /* patch */ static Future<Process> start(String executable, |
| 7 List<String> arguments, |
| 8 [ProcessOptions options]) { |
| 9 _ProcessImpl process = new _ProcessImpl(executable, arguments, options); |
| 10 return process._start(); |
| 11 } |
| 12 |
| 13 /* patch */ static Future<ProcessResult> run(String executable, |
| 14 List<String> arguments, |
| 15 [ProcessOptions options]) { |
| 16 return new _NonInteractiveProcess(executable, arguments, options)._result; |
| 17 } |
| 18 } |
| 19 |
| 20 |
| 21 patch class _ProcessUtils { |
| 22 /* patch */ static _exit(int status) native "Exit"; |
| 23 } |
| 24 |
6 | 25 |
7 class _ProcessStartStatus { | 26 class _ProcessStartStatus { |
8 int _errorCode; // Set to OS error code if process start failed. | 27 int _errorCode; // Set to OS error code if process start failed. |
9 String _errorMessage; // Set to OS error message if process start failed. | 28 String _errorMessage; // Set to OS error message if process start failed. |
10 } | 29 } |
11 | 30 |
12 | 31 |
13 class _Process extends NativeFieldWrapperClass1 implements Process { | 32 class _ProcessImpl extends NativeFieldWrapperClass1 implements Process { |
14 static Future<ProcessResult> run(String path, | 33 _ProcessImpl(String path, List<String> arguments, ProcessOptions options) { |
15 List<String> arguments, | |
16 [ProcessOptions options]) { | |
17 return new _NonInteractiveProcess(path, arguments, options)._result; | |
18 } | |
19 | |
20 static Future<Process> start(String path, | |
21 List<String> arguments, | |
22 ProcessOptions options) { | |
23 _Process process = new _Process(path, arguments, options); | |
24 return process._start(); | |
25 } | |
26 | |
27 _Process(String path, List<String> arguments, ProcessOptions options) { | |
28 if (path is !String) { | 34 if (path is !String) { |
29 throw new ArgumentError("Path is not a String: $path"); | 35 throw new ArgumentError("Path is not a String: $path"); |
30 } | 36 } |
31 _path = path; | 37 _path = path; |
32 | 38 |
33 if (arguments is !List) { | 39 if (arguments is !List) { |
34 throw new ArgumentError("Arguments is not a List: $arguments"); | 40 throw new ArgumentError("Arguments is not a List: $arguments"); |
35 } | 41 } |
36 int len = arguments.length; | 42 int len = arguments.length; |
37 _arguments = new List<String>(len); | 43 _arguments = new List<String>(len); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 if (options.stderrEncoding !== null) { | 285 if (options.stderrEncoding !== null) { |
280 stderrEncoding = options.stderrEncoding; | 286 stderrEncoding = options.stderrEncoding; |
281 if (stderrEncoding is !Encoding) { | 287 if (stderrEncoding is !Encoding) { |
282 throw new ArgumentError( | 288 throw new ArgumentError( |
283 'stderrEncoding option is not an encoding: $stderrEncoding'); | 289 'stderrEncoding option is not an encoding: $stderrEncoding'); |
284 } | 290 } |
285 } | 291 } |
286 } | 292 } |
287 | 293 |
288 // Start the underlying process. | 294 // Start the underlying process. |
289 var processFuture = new _Process(path, arguments, options)._start(); | 295 var processFuture = new _ProcessImpl(path, arguments, options)._start(); |
290 | 296 |
291 processFuture.then((Process p) { | 297 processFuture.then((Process p) { |
292 // Make sure the process stdin is closed. | 298 // Make sure the process stdin is closed. |
293 p.stdin.close; | 299 p.stdin.close; |
294 | 300 |
295 // Setup process exit handling. | 301 // Setup process exit handling. |
296 p.onExit = (exitCode) { | 302 p.onExit = (exitCode) { |
297 _exitCode = exitCode; | 303 _exitCode = exitCode; |
298 _checkDone(); | 304 _checkDone(); |
299 }; | 305 }; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 356 |
351 class _ProcessResult implements ProcessResult { | 357 class _ProcessResult implements ProcessResult { |
352 const _ProcessResult(int this.exitCode, | 358 const _ProcessResult(int this.exitCode, |
353 String this.stdout, | 359 String this.stdout, |
354 String this.stderr); | 360 String this.stderr); |
355 | 361 |
356 final int exitCode; | 362 final int exitCode; |
357 final String stdout; | 363 final String stdout; |
358 final String stderr; | 364 final String stderr; |
359 } | 365 } |
OLD | NEW |