Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Unified Diff: runtime/bin/process_patch.dart

Issue 16309014: Add support for binary stdout/stderr data when using Process.run (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Removed debug print Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/io/process.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/process_patch.dart
diff --git a/runtime/bin/process_patch.dart b/runtime/bin/process_patch.dart
index 0acd6c0498172154f50b4b0cd2eaf2be84df3599..f74e814af0856df0fb184d4e0ee76b6960e982d8 100644
--- a/runtime/bin/process_patch.dart
+++ b/runtime/bin/process_patch.dart
@@ -337,8 +337,8 @@ Future<ProcessResult> _runNonInteractiveProcess(String path,
Encoding stdoutEncoding,
Encoding stderrEncoding) {
// Extract output encoding options and verify arguments.
- if (stdoutEncoding == null) stdoutEncoding = Encoding.SYSTEM;
- if (stderrEncoding == null) stderrEncoding = Encoding.SYSTEM;
+ if (stdoutEncoding == null) stdoutEncoding = Encoding.BINARY;
Anders Johnsen 2013/06/13 09:02:07 Why BINARY here? I suppose we still default to SYS
Søren Gjesse 2013/06/13 10:27:12 The default in the signature for Process.run is st
+ if (stderrEncoding == null) stderrEncoding = Encoding.BINARY;
// Start the underlying process.
return Process.start(path,
@@ -351,30 +351,35 @@ Future<ProcessResult> _runNonInteractiveProcess(String path,
// Make sure the process stdin is closed.
p.stdin.close();
- // Setup stdout handling.
- Future<StringBuffer> stdout = p.stdout
- .transform(new StringDecoder(stdoutEncoding))
- .fold(
- new StringBuffer(),
- (buf, data) {
- buf.write(data);
- return buf;
- });
-
- Future<StringBuffer> stderr = p.stderr
- .transform(new StringDecoder(stderrEncoding))
- .fold(
- new StringBuffer(),
- (buf, data) {
- buf.write(data);
- return buf;
- });
+ // Setup stdout and stderr handling.
+ Future foldStream(Stream<List<int>> stream, Encoding encoding) {
+ if (encoding == Encoding.BINARY) {
+ return stream
+ .fold(
+ new _BufferList(),
+ (buf, data) {
+ buf.add(data);
+ return buf;
+ })
+ .then((buf) => buf.readBytes());
+ } else {
+ return stream
+ .transform(new StringDecoder(encoding))
+ .fold(
+ new StringBuffer(),
+ (buf, data) {
+ buf.write(data);
+ return buf;
+ })
+ .then((sb) => sb.toString());
+ }
+ }
+
+ Future stdout = foldStream(p.stdout, stdoutEncoding);
+ Future stderr = foldStream(p.stderr, stderrEncoding);
return Future.wait([p.exitCode, stdout, stderr]).then((result) {
- return new _ProcessResult(pid,
- result[0],
- result[1].toString(),
- result[2].toString());
+ return new _ProcessResult(pid, result[0], result[1], result[2]);
});
});
}
@@ -383,11 +388,11 @@ Future<ProcessResult> _runNonInteractiveProcess(String path,
class _ProcessResult implements ProcessResult {
const _ProcessResult(int this.pid,
int this.exitCode,
- String this.stdout,
- String this.stderr);
+ this.stdout,
+ this.stderr);
final int pid;
final int exitCode;
- final String stdout;
- final String stderr;
+ final stdout;
+ final stderr;
}
« no previous file with comments | « no previous file | sdk/lib/io/process.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698