| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 _WindowsCodePageDecoder { | 5 patch class _WindowsCodePageDecoder { |
| 6 /* patch */ static String _decodeBytes(List<int> bytes) | 6 /* patch */ static String _decodeBytes(List<int> bytes) |
| 7 native "SystemEncodingToString"; | 7 native "SystemEncodingToString"; |
| 8 } | 8 } |
| 9 | 9 |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 Encoding stderrEncoding: Encoding.SYSTEM}) { | 42 Encoding stderrEncoding: Encoding.SYSTEM}) { |
| 43 return _runNonInteractiveProcess(executable, | 43 return _runNonInteractiveProcess(executable, |
| 44 arguments, | 44 arguments, |
| 45 workingDirectory, | 45 workingDirectory, |
| 46 environment, | 46 environment, |
| 47 includeParentEnvironment, | 47 includeParentEnvironment, |
| 48 runInShell, | 48 runInShell, |
| 49 stdoutEncoding, | 49 stdoutEncoding, |
| 50 stderrEncoding); | 50 stderrEncoding); |
| 51 } | 51 } |
| 52 |
| 53 /* patch */ static ProcessResult runSync( |
| 54 String executable, |
| 55 List<String> arguments, |
| 56 {String workingDirectory, |
| 57 Map<String, String> environment, |
| 58 bool includeParentEnvironment: true, |
| 59 bool runInShell: false, |
| 60 Encoding stdoutEncoding: Encoding.SYSTEM, |
| 61 Encoding stderrEncoding: Encoding.SYSTEM}) { |
| 62 return _runNonInteractiveProcessSync(executable, |
| 63 arguments, |
| 64 workingDirectory, |
| 65 environment, |
| 66 includeParentEnvironment, |
| 67 runInShell, |
| 68 stdoutEncoding, |
| 69 stderrEncoding); |
| 70 } |
| 52 } | 71 } |
| 53 | 72 |
| 54 | 73 |
| 55 patch class _ProcessUtils { | 74 patch class _ProcessUtils { |
| 56 /* patch */ static void _exit(int status) native "Process_Exit"; | 75 /* patch */ static void _exit(int status) native "Process_Exit"; |
| 57 /* patch */ static void _setExitCode(int status) | 76 /* patch */ static void _setExitCode(int status) |
| 58 native "Process_SetExitCode"; | 77 native "Process_SetExitCode"; |
| 59 /* patch */ static void _sleep(int millis) native "Process_Sleep"; | 78 /* patch */ static void _sleep(int millis) native "Process_Sleep"; |
| 60 /* patch */ static int _pid(Process process) native "Process_Pid"; | 79 /* patch */ static int _pid(Process process) native "Process_Pid"; |
| 61 } | 80 } |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 if (exitDataRead == EXIT_DATA_SIZE) { | 290 if (exitDataRead == EXIT_DATA_SIZE) { |
| 272 handleExit(); | 291 handleExit(); |
| 273 } | 292 } |
| 274 }); | 293 }); |
| 275 | 294 |
| 276 completer.complete(this); | 295 completer.complete(this); |
| 277 }); | 296 }); |
| 278 return completer.future; | 297 return completer.future; |
| 279 } | 298 } |
| 280 | 299 |
| 300 ProcessResult _runAndWait(Encoding stdoutEncoding, |
| 301 Encoding stderrEncoding) { |
| 302 var status = new _ProcessStartStatus(); |
| 303 bool success = _startNative(_path, |
| 304 _arguments, |
| 305 _workingDirectory, |
| 306 _environment, |
| 307 _stdin._sink._nativeSocket, |
| 308 _stdout._stream._nativeSocket, |
| 309 _stderr._stream._nativeSocket, |
| 310 _exitHandler._nativeSocket, |
| 311 status); |
| 312 if (!success) { |
| 313 throw new ProcessException(_path, |
| 314 _arguments, |
| 315 status._errorMessage, |
| 316 status._errorCode); |
| 317 } |
| 318 |
| 319 var result = _wait( |
| 320 _stdin._sink._nativeSocket, |
| 321 _stdout._stream._nativeSocket, |
| 322 _stderr._stream._nativeSocket, |
| 323 _exitHandler._nativeSocket); |
| 324 |
| 325 getOutput(output, encoding) { |
| 326 if (stderrEncoding == null) return output; |
| 327 return _decodeString(output, encoding); |
| 328 } |
| 329 |
| 330 return new _ProcessResult( |
| 331 result[0], |
| 332 result[1], |
| 333 getOutput(result[2], stdoutEncoding), |
| 334 getOutput(result[3], stderrEncoding)); |
| 335 } |
| 336 |
| 281 bool _startNative(String path, | 337 bool _startNative(String path, |
| 282 List<String> arguments, | 338 List<String> arguments, |
| 283 String workingDirectory, | 339 String workingDirectory, |
| 284 List<String> environment, | 340 List<String> environment, |
| 285 _NativeSocket stdin, | 341 _NativeSocket stdin, |
| 286 _NativeSocket stdout, | 342 _NativeSocket stdout, |
| 287 _NativeSocket stderr, | 343 _NativeSocket stderr, |
| 288 _NativeSocket exitHandler, | 344 _NativeSocket exitHandler, |
| 289 _ProcessStartStatus status) native "Process_Start"; | 345 _ProcessStartStatus status) native "Process_Start"; |
| 290 | 346 |
| 347 _wait(_NativeSocket stdin, |
| 348 _NativeSocket stdout, |
| 349 _NativeSocket stderr, |
| 350 _NativeSocket exitHandler) native "Process_Wait"; |
| 351 |
| 291 Stream<List<int>> get stdout { | 352 Stream<List<int>> get stdout { |
| 292 return _stdout; | 353 return _stdout; |
| 293 } | 354 } |
| 294 | 355 |
| 295 Stream<List<int>> get stderr { | 356 Stream<List<int>> get stderr { |
| 296 return _stderr; | 357 return _stderr; |
| 297 } | 358 } |
| 298 | 359 |
| 299 IOSink get stdin { | 360 IOSink get stdin { |
| 300 return _stdin; | 361 return _stdin; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 | 437 |
| 377 Future stdout = foldStream(p.stdout, stdoutEncoding); | 438 Future stdout = foldStream(p.stdout, stdoutEncoding); |
| 378 Future stderr = foldStream(p.stderr, stderrEncoding); | 439 Future stderr = foldStream(p.stderr, stderrEncoding); |
| 379 | 440 |
| 380 return Future.wait([p.exitCode, stdout, stderr]).then((result) { | 441 return Future.wait([p.exitCode, stdout, stderr]).then((result) { |
| 381 return new _ProcessResult(pid, result[0], result[1], result[2]); | 442 return new _ProcessResult(pid, result[0], result[1], result[2]); |
| 382 }); | 443 }); |
| 383 }); | 444 }); |
| 384 } | 445 } |
| 385 | 446 |
| 447 ProcessResult _runNonInteractiveProcessSync( |
| 448 String executable, |
| 449 List<String> arguments, |
| 450 String workingDirectory, |
| 451 Map<String, String> environment, |
| 452 bool includeParentEnvironment, |
| 453 bool runInShell, |
| 454 Encoding stdoutEncoding, |
| 455 Encoding stderrEncoding) { |
| 456 var process = new _ProcessImpl(executable, |
| 457 arguments, |
| 458 workingDirectory, |
| 459 environment, |
| 460 includeParentEnvironment, |
| 461 runInShell); |
| 462 return process._runAndWait(stdoutEncoding, stderrEncoding); |
| 463 } |
| 464 |
| 386 | 465 |
| 387 class _ProcessResult implements ProcessResult { | 466 class _ProcessResult implements ProcessResult { |
| 388 const _ProcessResult(int this.pid, | 467 const _ProcessResult(int this.pid, |
| 389 int this.exitCode, | 468 int this.exitCode, |
| 390 this.stdout, | 469 this.stdout, |
| 391 this.stderr); | 470 this.stderr); |
| 392 | 471 |
| 393 final int pid; | 472 final int pid; |
| 394 final int exitCode; | 473 final int exitCode; |
| 395 final stdout; | 474 final stdout; |
| 396 final stderr; | 475 final stderr; |
| 397 } | 476 } |
| OLD | NEW |