| 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 patch class Process { | 5 patch class Process { |
| 6 /* patch */ static Future<Process> start(String executable, | 6 /* patch */ static Future<Process> start(String executable, |
| 7 List<String> arguments, | 7 List<String> arguments, |
| 8 [ProcessOptions options]) { | 8 [ProcessOptions options]) { |
| 9 _ProcessImpl process = new _ProcessImpl(executable, arguments, options); | 9 _ProcessImpl process = new _ProcessImpl(executable, arguments, options); |
| 10 return process._start(); | 10 return process._start(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 var arg = arguments[i]; | 45 var arg = arguments[i]; |
| 46 if (arg is !String) { | 46 if (arg is !String) { |
| 47 throw new ArgumentError("Non-string argument: $arg"); | 47 throw new ArgumentError("Non-string argument: $arg"); |
| 48 } | 48 } |
| 49 _arguments[i] = arguments[i]; | 49 _arguments[i] = arguments[i]; |
| 50 if (Platform.operatingSystem == 'windows') { | 50 if (Platform.operatingSystem == 'windows') { |
| 51 _arguments[i] = _windowsArgumentEscape(_arguments[i]); | 51 _arguments[i] = _windowsArgumentEscape(_arguments[i]); |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 | 54 |
| 55 if (options !== null && options.workingDirectory !== null) { | 55 if (options != null && options.workingDirectory != null) { |
| 56 _workingDirectory = options.workingDirectory; | 56 _workingDirectory = options.workingDirectory; |
| 57 if (_workingDirectory is !String) { | 57 if (_workingDirectory is !String) { |
| 58 throw new ArgumentError( | 58 throw new ArgumentError( |
| 59 "WorkingDirectory is not a String: $_workingDirectory"); | 59 "WorkingDirectory is not a String: $_workingDirectory"); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 if (options !== null && options.environment !== null) { | 63 if (options != null && options.environment != null) { |
| 64 var env = options.environment; | 64 var env = options.environment; |
| 65 if (env is !Map) { | 65 if (env is !Map) { |
| 66 throw new ArgumentError("Environment is not a map: $env"); | 66 throw new ArgumentError("Environment is not a map: $env"); |
| 67 } | 67 } |
| 68 _environment = []; | 68 _environment = []; |
| 69 env.forEach((key, value) { | 69 env.forEach((key, value) { |
| 70 if (key is !String || value is !String) { | 70 if (key is !String || value is !String) { |
| 71 throw new ArgumentError( | 71 throw new ArgumentError( |
| 72 "Environment key or value is not a string: ($key, $value)"); | 72 "Environment key or value is not a string: ($key, $value)"); |
| 73 } | 73 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 183 |
| 184 int exitCode(List<int> ints) { | 184 int exitCode(List<int> ints) { |
| 185 var code = _intFromBytes(ints, 0); | 185 var code = _intFromBytes(ints, 0); |
| 186 var negative = _intFromBytes(ints, 4); | 186 var negative = _intFromBytes(ints, 4); |
| 187 assert(negative == 0 || negative == 1); | 187 assert(negative == 0 || negative == 1); |
| 188 return (negative == 0) ? code : -code; | 188 return (negative == 0) ? code : -code; |
| 189 } | 189 } |
| 190 | 190 |
| 191 void handleExit() { | 191 void handleExit() { |
| 192 _ended = true; | 192 _ended = true; |
| 193 if (_onExit !== null) { | 193 if (_onExit != null) { |
| 194 _onExit(exitCode(exitDataBuffer)); | 194 _onExit(exitCode(exitDataBuffer)); |
| 195 } | 195 } |
| 196 _out.close(); | 196 _out.close(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 exitDataRead += _exitHandler.inputStream.readInto( | 199 exitDataRead += _exitHandler.inputStream.readInto( |
| 200 exitDataBuffer, exitDataRead, EXIT_DATA_SIZE - exitDataRead); | 200 exitDataBuffer, exitDataRead, EXIT_DATA_SIZE - exitDataRead); |
| 201 if (exitDataRead == EXIT_DATA_SIZE) { | 201 if (exitDataRead == EXIT_DATA_SIZE) { |
| 202 _exitHandler.close(); | 202 _exitHandler.close(); |
| 203 handleExit(); | 203 handleExit(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 // _NonInteractiveProcess is used to implement the Process.run | 270 // _NonInteractiveProcess is used to implement the Process.run |
| 271 // method. | 271 // method. |
| 272 class _NonInteractiveProcess { | 272 class _NonInteractiveProcess { |
| 273 _NonInteractiveProcess(String path, | 273 _NonInteractiveProcess(String path, |
| 274 List<String> arguments, | 274 List<String> arguments, |
| 275 ProcessOptions options) { | 275 ProcessOptions options) { |
| 276 _completer = new Completer<ProcessResult>(); | 276 _completer = new Completer<ProcessResult>(); |
| 277 // Extract output encoding options and verify arguments. | 277 // Extract output encoding options and verify arguments. |
| 278 var stdoutEncoding = Encoding.UTF_8; | 278 var stdoutEncoding = Encoding.UTF_8; |
| 279 var stderrEncoding = Encoding.UTF_8; | 279 var stderrEncoding = Encoding.UTF_8; |
| 280 if (options !== null) { | 280 if (options != null) { |
| 281 if (options.stdoutEncoding !== null) { | 281 if (options.stdoutEncoding != null) { |
| 282 stdoutEncoding = options.stdoutEncoding; | 282 stdoutEncoding = options.stdoutEncoding; |
| 283 if (stdoutEncoding is !Encoding) { | 283 if (stdoutEncoding is !Encoding) { |
| 284 throw new ArgumentError( | 284 throw new ArgumentError( |
| 285 'stdoutEncoding option is not an encoding: $stdoutEncoding'); | 285 'stdoutEncoding option is not an encoding: $stdoutEncoding'); |
| 286 } | 286 } |
| 287 } | 287 } |
| 288 if (options.stderrEncoding !== null) { | 288 if (options.stderrEncoding != null) { |
| 289 stderrEncoding = options.stderrEncoding; | 289 stderrEncoding = options.stderrEncoding; |
| 290 if (stderrEncoding is !Encoding) { | 290 if (stderrEncoding is !Encoding) { |
| 291 throw new ArgumentError( | 291 throw new ArgumentError( |
| 292 'stderrEncoding option is not an encoding: $stderrEncoding'); | 292 'stderrEncoding option is not an encoding: $stderrEncoding'); |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 } | 295 } |
| 296 | 296 |
| 297 // Start the underlying process. | 297 // Start the underlying process. |
| 298 var processFuture = new _ProcessImpl(path, arguments, options)._start(); | 298 var processFuture = new _ProcessImpl(path, arguments, options)._start(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 | 359 |
| 360 class _ProcessResult implements ProcessResult { | 360 class _ProcessResult implements ProcessResult { |
| 361 const _ProcessResult(int this.exitCode, | 361 const _ProcessResult(int this.exitCode, |
| 362 String this.stdout, | 362 String this.stdout, |
| 363 String this.stderr); | 363 String this.stderr); |
| 364 | 364 |
| 365 final int exitCode; | 365 final int exitCode; |
| 366 final String stdout; | 366 final String stdout; |
| 367 final String stderr; | 367 final String stderr; |
| 368 } | 368 } |
| OLD | NEW |