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

Side by Side Diff: tests/standalone/io/process_std_io_script2.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
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 // Utility script to echo strings in various formats to stdout or 5 // Utility script to echo strings in various formats to stdout or
6 // stderr. 6 // stderr.
7 7
8 import "dart:io"; 8 import "dart:io";
9 9
10 writeData(data, encoding, stream) { 10 writeData(data, encoding, stream) {
11 if (stream == "stdout") { 11 if (stream == "stdout") {
12 stdout.encoding = encoding; 12 if (encoding == Encoding.BINARY) {
13 stdout.write(data); 13 stdout.add(data);
14 } else {
15 stdout.encoding = encoding;
16 stdout.write(data);
17 }
14 } else if (stream == "stderr") { 18 } else if (stream == "stderr") {
15 stderr.encoding = encoding; 19 if (encoding == Encoding.BINARY) {
16 stderr.write(data); 20 stderr.add(data);
21 } else {
22 stderr.encoding = encoding;
23 stderr.write(data);
24 }
17 } 25 }
18 } 26 }
19 27
20 main() { 28 main() {
21 var asciiString = 'abc'; 29 var asciiString = 'abc';
22 var latin1String = 'æøå'; 30 var latin1String = 'æøå';
23 var utf8String = new String.fromCharCodes([955]); 31 var utf8String = new String.fromCharCodes([955]);
32 var binary = [0, 1, 2];
24 var options = new Options(); 33 var options = new Options();
25 if (options.arguments.length > 1) { 34 if (options.arguments.length > 1) {
26 var stream = options.arguments[1]; 35 var stream = options.arguments[1];
27 if (options.arguments[0] == "ascii") { 36 if (options.arguments[0] == "ascii") {
28 writeData(asciiString, Encoding.ASCII, stream); 37 writeData(asciiString, Encoding.ASCII, stream);
29 } else if (options.arguments[0] == "latin1") { 38 } else if (options.arguments[0] == "latin1") {
30 writeData(latin1String, Encoding.ISO_8859_1, stream); 39 writeData(latin1String, Encoding.ISO_8859_1, stream);
31 } else if (options.arguments[0] == "utf8") { 40 } else if (options.arguments[0] == "utf8") {
32 writeData(utf8String, Encoding.UTF_8, stream); 41 writeData(utf8String, Encoding.UTF_8, stream);
42 } else if (options.arguments[0] == "binary") {
43 writeData(binary, Encoding.BINARY, stream);
33 } 44 }
34 } 45 }
35 } 46 }
OLDNEW
« runtime/bin/process_patch.dart ('K') | « tests/standalone/io/process_run_output_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698