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 // Utility script to echo stdin to stdout or stderr or both. | 5 // Utility script to echo stdin to stdout or stderr or both. |
6 | 6 |
7 import "dart:io"; | 7 import "dart:io"; |
8 | 8 |
9 main() { | 9 main() { |
10 var options = new Options(); | 10 var options = new Options(); |
| 11 if (stdioType(stdin) is !StdioType) exit(1); |
| 12 if (stdioType(stdout) is !StdioType) exit(1); |
| 13 if (stdioType(stderr) is !StdioType) exit(1); |
| 14 if (stdioType(stdin).name != options.arguments[1]) { |
| 15 throw stdioType(stdin).name; |
| 16 } |
| 17 if (stdioType(stdout).name != options.arguments[2]) { |
| 18 throw stdioType(stdout).name; |
| 19 } |
| 20 if (stdioType(stderr).name != options.arguments[3]) { |
| 21 throw stdioType(stderr).name; |
| 22 } |
11 if (options.arguments.length > 0) { | 23 if (options.arguments.length > 0) { |
12 if (options.arguments[0] == "0") { | 24 if (options.arguments[0] == "0") { |
13 stdin.pipe(stdout); | 25 stdin.pipe(stdout); |
14 } else if (options.arguments[0] == "1") { | 26 } else if (options.arguments[0] == "1") { |
15 stdin.pipe(stderr); | 27 stdin.pipe(stderr); |
16 } else if (options.arguments[0] == "2") { | 28 } else if (options.arguments[0] == "2") { |
17 stdin.listen((data) { | 29 stdin.listen((data) { |
18 stdout.writeBytes(data); | 30 stdout.writeBytes(data); |
19 stderr.writeBytes(data); | 31 stderr.writeBytes(data); |
20 }); | 32 }); |
21 } | 33 } |
22 } | 34 } |
23 } | 35 } |
OLD | NEW |