| 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 _exit(int status) native "Exit"; |
| 6 | 6 |
| 7 class _ProcessStartStatus { | 7 class _ProcessStartStatus { |
| 8 int _errorCode; // Set to OS error code if process start failed. | 8 int _errorCode; // Set to OS error code if process start failed. |
| 9 String _errorMessage; // Set to OS error message if process start failed. | 9 String _errorMessage; // Set to OS error message if process start failed. |
| 10 } | 10 } |
| 11 | 11 |
| 12 | 12 |
| 13 class _Process extends NativeFieldWrapperClass1 implements Process { | 13 class _Process extends NativeFieldWrapperClass1 implements Process { |
| 14 static Future<ProcessResult> run(String path, | 14 static Future<ProcessResult> run(String path, |
| 15 List<String> arguments, | 15 List<String> arguments, |
| 16 [ProcessOptions options]) { | 16 [ProcessOptions options]) { |
| 17 return new _NonInteractiveProcess._start(path, arguments, options)._result; | 17 return new _NonInteractiveProcess._start(path, arguments, options)._result; |
| 18 } | 18 } |
| 19 | 19 |
| 20 _Process.start(String path, | 20 _Process.start(String path, |
| 21 List<String> arguments, | 21 List<String> arguments, |
| 22 ProcessOptions options) { | 22 ProcessOptions options) { |
| 23 if (path is !String) { | 23 if (path is !String) { |
| 24 throw new IllegalArgumentException("Path is not a String: $path"); | 24 throw new ArgumentError("Path is not a String: $path"); |
| 25 } | 25 } |
| 26 _path = path; | 26 _path = path; |
| 27 | 27 |
| 28 if (arguments is !List) { | 28 if (arguments is !List) { |
| 29 throw new IllegalArgumentException("Arguments is not a List: $arguments"); | 29 throw new ArgumentError("Arguments is not a List: $arguments"); |
| 30 } | 30 } |
| 31 int len = arguments.length; | 31 int len = arguments.length; |
| 32 _arguments = new ObjectArray<String>(len); | 32 _arguments = new ObjectArray<String>(len); |
| 33 for (int i = 0; i < len; i++) { | 33 for (int i = 0; i < len; i++) { |
| 34 var arg = arguments[i]; | 34 var arg = arguments[i]; |
| 35 if (arg is !String) { | 35 if (arg is !String) { |
| 36 throw new IllegalArgumentException("Non-string argument: $arg"); | 36 throw new ArgumentError("Non-string argument: $arg"); |
| 37 } | 37 } |
| 38 _arguments[i] = arguments[i]; | 38 _arguments[i] = arguments[i]; |
| 39 if (Platform.operatingSystem == 'windows') { | 39 if (Platform.operatingSystem == 'windows') { |
| 40 _arguments[i] = _windowsArgumentEscape(_arguments[i]); | 40 _arguments[i] = _windowsArgumentEscape(_arguments[i]); |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 | 43 |
| 44 if (options !== null && options.workingDirectory !== null) { | 44 if (options !== null && options.workingDirectory !== null) { |
| 45 _workingDirectory = options.workingDirectory; | 45 _workingDirectory = options.workingDirectory; |
| 46 if (_workingDirectory is !String) { | 46 if (_workingDirectory is !String) { |
| 47 throw new IllegalArgumentException( | 47 throw new ArgumentError( |
| 48 "WorkingDirectory is not a String: $_workingDirectory"); | 48 "WorkingDirectory is not a String: $_workingDirectory"); |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 if (options !== null && options.environment !== null) { | 52 if (options !== null && options.environment !== null) { |
| 53 var env = options.environment; | 53 var env = options.environment; |
| 54 if (env is !Map) { | 54 if (env is !Map) { |
| 55 throw new IllegalArgumentException("Environment is not a map: $env"); | 55 throw new ArgumentError("Environment is not a map: $env"); |
| 56 } | 56 } |
| 57 _environment = []; | 57 _environment = []; |
| 58 env.forEach((key, value) { | 58 env.forEach((key, value) { |
| 59 if (key is !String || value is !String) { | 59 if (key is !String || value is !String) { |
| 60 throw new IllegalArgumentException( | 60 throw new ArgumentError( |
| 61 "Environment key or value is not a string: ($key, $value)"); | 61 "Environment key or value is not a string: ($key, $value)"); |
| 62 } | 62 } |
| 63 _environment.add('$key=$value'); | 63 _environment.add('$key=$value'); |
| 64 }); | 64 }); |
| 65 } | 65 } |
| 66 | 66 |
| 67 _in = new _Socket._internalReadOnly(); // stdout coming from process. | 67 _in = new _Socket._internalReadOnly(); // stdout coming from process. |
| 68 _out = new _Socket._internalWriteOnly(); // stdin going to process. | 68 _out = new _Socket._internalWriteOnly(); // stdin going to process. |
| 69 _err = new _Socket._internalReadOnly(); // stderr coming from process. | 69 _err = new _Socket._internalReadOnly(); // stderr coming from process. |
| 70 _exitHandler = new _Socket._internalReadOnly(); | 70 _exitHandler = new _Socket._internalReadOnly(); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 217 |
| 218 OutputStream get stdin { | 218 OutputStream get stdin { |
| 219 if (_closed) { | 219 if (_closed) { |
| 220 throw new ProcessException("Process closed"); | 220 throw new ProcessException("Process closed"); |
| 221 } | 221 } |
| 222 return _out.outputStream; | 222 return _out.outputStream; |
| 223 } | 223 } |
| 224 | 224 |
| 225 void kill([ProcessSignal signal = ProcessSignal.SIGTERM]) { | 225 void kill([ProcessSignal signal = ProcessSignal.SIGTERM]) { |
| 226 if (signal is! ProcessSignal) { | 226 if (signal is! ProcessSignal) { |
| 227 throw new IllegalArgumentException( | 227 throw new ArgumentError( |
| 228 "Argument 'signal' must be a ProcessSignal"); | 228 "Argument 'signal' must be a ProcessSignal"); |
| 229 } | 229 } |
| 230 if (!_started) { | 230 if (!_started) { |
| 231 var e = new ProcessException("Cannot kill process that is not started"); | 231 var e = new ProcessException("Cannot kill process that is not started"); |
| 232 _reportError(e); | 232 _reportError(e); |
| 233 return; | 233 return; |
| 234 } | 234 } |
| 235 if (_ended) { | 235 if (_ended) { |
| 236 return; | 236 return; |
| 237 } | 237 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 List<String> arguments, | 308 List<String> arguments, |
| 309 ProcessOptions options) { | 309 ProcessOptions options) { |
| 310 _completer = new Completer<ProcessResult>(); | 310 _completer = new Completer<ProcessResult>(); |
| 311 // Extract output encoding options and verify arguments. | 311 // Extract output encoding options and verify arguments. |
| 312 var stdoutEncoding = Encoding.UTF_8; | 312 var stdoutEncoding = Encoding.UTF_8; |
| 313 var stderrEncoding = Encoding.UTF_8; | 313 var stderrEncoding = Encoding.UTF_8; |
| 314 if (options !== null) { | 314 if (options !== null) { |
| 315 if (options.stdoutEncoding !== null) { | 315 if (options.stdoutEncoding !== null) { |
| 316 stdoutEncoding = options.stdoutEncoding; | 316 stdoutEncoding = options.stdoutEncoding; |
| 317 if (stdoutEncoding is !Encoding) { | 317 if (stdoutEncoding is !Encoding) { |
| 318 throw new IllegalArgumentException( | 318 throw new ArgumentError( |
| 319 'stdoutEncoding option is not an encoding: $stdoutEncoding'); | 319 'stdoutEncoding option is not an encoding: $stdoutEncoding'); |
| 320 } | 320 } |
| 321 } | 321 } |
| 322 if (options.stderrEncoding !== null) { | 322 if (options.stderrEncoding !== null) { |
| 323 stderrEncoding = options.stderrEncoding; | 323 stderrEncoding = options.stderrEncoding; |
| 324 if (stderrEncoding is !Encoding) { | 324 if (stderrEncoding is !Encoding) { |
| 325 throw new IllegalArgumentException( | 325 throw new ArgumentError( |
| 326 'stderrEncoding option is not an encoding: $stderrEncoding'); | 326 'stderrEncoding option is not an encoding: $stderrEncoding'); |
| 327 } | 327 } |
| 328 } | 328 } |
| 329 } | 329 } |
| 330 | 330 |
| 331 // Start the underlying process. | 331 // Start the underlying process. |
| 332 _process = new _Process.start(path, arguments, options); | 332 _process = new _Process.start(path, arguments, options); |
| 333 | 333 |
| 334 // Make sure stdin is closed. | 334 // Make sure stdin is closed. |
| 335 _process.onStart = _process.stdin.close; | 335 _process.onStart = _process.stdin.close; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 | 390 |
| 391 class _ProcessResult implements ProcessResult { | 391 class _ProcessResult implements ProcessResult { |
| 392 const _ProcessResult(int this.exitCode, | 392 const _ProcessResult(int this.exitCode, |
| 393 String this.stdout, | 393 String this.stdout, |
| 394 String this.stderr); | 394 String this.stderr); |
| 395 | 395 |
| 396 final int exitCode; | 396 final int exitCode; |
| 397 final String stdout; | 397 final String stdout; |
| 398 final String stderr; | 398 final String stderr; |
| 399 } | 399 } |
| OLD | NEW |