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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/io/process.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 // _NonInteractiveProcess is used to implement the Process.run 330 // _NonInteractiveProcess is used to implement the Process.run
331 // method. 331 // method.
332 Future<ProcessResult> _runNonInteractiveProcess(String path, 332 Future<ProcessResult> _runNonInteractiveProcess(String path,
333 List<String> arguments, 333 List<String> arguments,
334 String workingDirectory, 334 String workingDirectory,
335 Map<String, String> environment, 335 Map<String, String> environment,
336 bool runInShell, 336 bool runInShell,
337 Encoding stdoutEncoding, 337 Encoding stdoutEncoding,
338 Encoding stderrEncoding) { 338 Encoding stderrEncoding) {
339 // Extract output encoding options and verify arguments. 339 // Extract output encoding options and verify arguments.
340 if (stdoutEncoding == null) stdoutEncoding = Encoding.SYSTEM; 340 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
341 if (stderrEncoding == null) stderrEncoding = Encoding.SYSTEM; 341 if (stderrEncoding == null) stderrEncoding = Encoding.BINARY;
342 342
343 // Start the underlying process. 343 // Start the underlying process.
344 return Process.start(path, 344 return Process.start(path,
345 arguments, 345 arguments,
346 workingDirectory: workingDirectory, 346 workingDirectory: workingDirectory,
347 environment: environment, 347 environment: environment,
348 runInShell: runInShell).then((Process p) { 348 runInShell: runInShell).then((Process p) {
349 int pid = p.pid; 349 int pid = p.pid;
350 350
351 // Make sure the process stdin is closed. 351 // Make sure the process stdin is closed.
352 p.stdin.close(); 352 p.stdin.close();
353 353
354 // Setup stdout handling. 354 // Setup stdout and stderr handling.
355 Future<StringBuffer> stdout = p.stdout 355 Future foldStream(Stream<List<int>> stream, Encoding encoding) {
356 .transform(new StringDecoder(stdoutEncoding)) 356 if (encoding == Encoding.BINARY) {
357 .fold( 357 return stream
358 new StringBuffer(), 358 .fold(
359 (buf, data) { 359 new _BufferList(),
360 buf.write(data); 360 (buf, data) {
361 return buf; 361 buf.add(data);
362 }); 362 return buf;
363 })
364 .then((buf) => buf.readBytes());
365 } else {
366 return stream
367 .transform(new StringDecoder(encoding))
368 .fold(
369 new StringBuffer(),
370 (buf, data) {
371 buf.write(data);
372 return buf;
373 })
374 .then((sb) => sb.toString());
375 }
376 }
363 377
364 Future<StringBuffer> stderr = p.stderr 378 Future stdout = foldStream(p.stdout, stdoutEncoding);
365 .transform(new StringDecoder(stderrEncoding)) 379 Future stderr = foldStream(p.stderr, stderrEncoding);
366 .fold(
367 new StringBuffer(),
368 (buf, data) {
369 buf.write(data);
370 return buf;
371 });
372 380
373 return Future.wait([p.exitCode, stdout, stderr]).then((result) { 381 return Future.wait([p.exitCode, stdout, stderr]).then((result) {
374 return new _ProcessResult(pid, 382 return new _ProcessResult(pid, result[0], result[1], result[2]);
375 result[0],
376 result[1].toString(),
377 result[2].toString());
378 }); 383 });
379 }); 384 });
380 } 385 }
381 386
382 387
383 class _ProcessResult implements ProcessResult { 388 class _ProcessResult implements ProcessResult {
384 const _ProcessResult(int this.pid, 389 const _ProcessResult(int this.pid,
385 int this.exitCode, 390 int this.exitCode,
386 String this.stdout, 391 this.stdout,
387 String this.stderr); 392 this.stderr);
388 393
389 final int pid; 394 final int pid;
390 final int exitCode; 395 final int exitCode;
391 final String stdout; 396 final stdout;
392 final String stderr; 397 final stderr;
393 } 398 }
OLDNEW
« 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