Chromium Code Reviews| 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 /** | 5 /** |
| 6 * Helper functionality to make working with IO easier. | 6 * Helper functionality to make working with IO easier. |
| 7 */ | 7 */ |
| 8 library io; | 8 library io; |
| 9 | 9 |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 args = flatten(["/c", executable, args]); | 492 args = flatten(["/c", executable, args]); |
| 493 executable = "cmd"; | 493 executable = "cmd"; |
| 494 } | 494 } |
| 495 | 495 |
| 496 final options = new ProcessOptions(); | 496 final options = new ProcessOptions(); |
| 497 if (workingDir != null) { | 497 if (workingDir != null) { |
| 498 options.workingDirectory = _getDirectory(workingDir).path; | 498 options.workingDirectory = _getDirectory(workingDir).path; |
| 499 } | 499 } |
| 500 options.environment = environment; | 500 options.environment = environment; |
| 501 | 501 |
| 502 final process = Process.start(executable, args, options); | 502 var future = Process.run(executable, args, options); |
| 503 | 503 return future.transform((result) { |
| 504 final outStream = new StringInputStream(process.stdout); | 504 return new PubProcessResult(result.stdout, result.stderr, result.exitCode); |
| 505 final processStdout = <String>[]; | 505 }); |
|
Bob Nystrom
2012/10/16 14:07:29
Well this is a distinct improvement. :)
This code
Anders Johnsen
2012/10/16 14:29:57
There is nothing wrong with the old code, other th
nweiz
2012/10/16 17:20:15
This doesn't support pipeStdout/pipeStderr. Either
Anders Johnsen
2012/10/17 07:05:25
Ahh, good point. Bob, is the piping needed in Pub?
Bob Nystrom
2012/10/17 16:25:52
It doesn't look like we're using that right now, s
| |
| 506 | |
| 507 final errStream = new StringInputStream(process.stderr); | |
| 508 final processStderr = <String>[]; | |
| 509 | |
| 510 final completer = new Completer<PubProcessResult>(); | |
| 511 | |
| 512 checkComplete() { | |
| 513 // Wait until the process is done and its output streams are closed. | |
| 514 if (!pipeStdout && !outStream.closed) return; | |
| 515 if (!pipeStderr && !errStream.closed) return; | |
| 516 if (exitCode == null) return; | |
| 517 | |
| 518 completer.complete(new PubProcessResult( | |
| 519 processStdout, processStderr, exitCode)); | |
| 520 } | |
| 521 | |
| 522 if (pipeStdout) { | |
| 523 process.stdout.pipe(stdout, close: false); | |
| 524 } else { | |
| 525 outStream.onLine = () => processStdout.add(outStream.readLine()); | |
| 526 outStream.onClosed = checkComplete; | |
| 527 outStream.onError = (error) => completer.completeException(error); | |
| 528 } | |
| 529 | |
| 530 if (pipeStderr) { | |
| 531 process.stderr.pipe(stderr, close: false); | |
| 532 } else { | |
| 533 errStream.onLine = () => processStderr.add(errStream.readLine()); | |
| 534 errStream.onClosed = checkComplete; | |
| 535 errStream.onError = (error) => completer.completeException(error); | |
| 536 } | |
| 537 | |
| 538 process.onExit = (actualExitCode) { | |
| 539 exitCode = actualExitCode; | |
| 540 checkComplete(); | |
| 541 }; | |
| 542 | |
| 543 process.onError = (error) => completer.completeException(error); | |
| 544 | |
| 545 return completer.future; | |
| 546 } | 506 } |
| 547 | 507 |
| 548 /** | 508 /** |
| 549 * Wraps [input] to provide a timeout. If [input] completes before | 509 * Wraps [input] to provide a timeout. If [input] completes before |
| 550 * [milliseconds] have passed, then the return value completes in the same way. | 510 * [milliseconds] have passed, then the return value completes in the same way. |
| 551 * However, if [milliseconds] pass before [input] has completed, it completes | 511 * However, if [milliseconds] pass before [input] has completed, it completes |
| 552 * with a [TimeoutException] with [message]. | 512 * with a [TimeoutException] with [message]. |
| 553 * | 513 * |
| 554 * Note that timing out will not cancel the asynchronous operation behind | 514 * Note that timing out will not cancel the asynchronous operation behind |
| 555 * [input]. | 515 * [input]. |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 785 return new Directory(entry); | 745 return new Directory(entry); |
| 786 } | 746 } |
| 787 | 747 |
| 788 /** | 748 /** |
| 789 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 749 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
| 790 */ | 750 */ |
| 791 Uri _getUri(uri) { | 751 Uri _getUri(uri) { |
| 792 if (uri is Uri) return uri; | 752 if (uri is Uri) return uri; |
| 793 return new Uri.fromString(uri); | 753 return new Uri.fromString(uri); |
| 794 } | 754 } |
| OLD | NEW |