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

Unified Diff: runtime/bin/stdio.dart

Issue 9360040: Handle stdio redirection in standalone VM (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revert test change Created 8 years, 10 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 | « runtime/bin/socket_impl.dart ('k') | tests/standalone/src/DartStdIOPipeTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/stdio.dart
diff --git a/runtime/bin/stdio.dart b/runtime/bin/stdio.dart
index 4f154fbe6d36e39da00a75e65a51fbd7205315da..495135ffeb0892092464099b52d8e12e888c3df8 100644
--- a/runtime/bin/stdio.dart
+++ b/runtime/bin/stdio.dart
@@ -2,31 +2,70 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-Socket _stdin;
+final int _STDIO_HANDLE_TYPE_TERMINAL = 0;
+final int _STDIO_HANDLE_TYPE_PIPE = 1;
+final int _STDIO_HANDLE_TYPE_FILE = 2;
+final int _STDIO_HANDLE_TYPE_OTHER = 3;
+
+
+InputStream _stdin;
+OutputStream _stdout;
+OutputStream _stderr;
+
+
+InputStream _getStdioInputStream() {
+ switch (_getStdioHandleType(0)) {
+ case _STDIO_HANDLE_TYPE_TERMINAL:
+ case _STDIO_HANDLE_TYPE_PIPE:
+ Socket s = new _Socket._internalReadOnly();
+ _getStdioHandle(s, 0);
+ return s.inputStream;
+ case _STDIO_HANDLE_TYPE_FILE:
+ return new _FileInputStream.fromStdio(0);
+ default:
+ throw new FileIOException("Unsupported stdin type");
+ }
+}
+
+
+OutputStream _getStdioOutputStream(int fd) {
+ assert(fd == 1 || fd == 2);
+ switch (_getStdioHandleType(fd)) {
+ case _STDIO_HANDLE_TYPE_TERMINAL:
+ case _STDIO_HANDLE_TYPE_PIPE:
+ Socket s = new _Socket._internalWriteOnly();
+ _getStdioHandle(s, fd);
+ return s.outputStream;
+ case _STDIO_HANDLE_TYPE_FILE:
+ return new _FileOutputStream.fromStdio(fd);
+ default:
+ throw new FileIOException("Unsupported stdin type");
+ }
+}
+
+
InputStream get stdin() {
if (_stdin == null) {
- _stdin = new _Socket._internalReadOnly();
- _getStdioHandle(_stdin, 0);
+ _stdin = _getStdioInputStream();
}
- return _stdin.inputStream;
+ return _stdin;
}
-Socket _stdout;
+
OutputStream get stdout() {
if (_stdout == null) {
- _stdout = new _Socket._internalWriteOnly();
- _getStdioHandle(_stdout, 1);
+ _stdout = _getStdioOutputStream(1);
}
- return _stdout.outputStream;
+ return _stdout;
}
-Socket _stderr;
+
OutputStream get stderr() {
if (_stderr == null) {
- _stderr = new _Socket._internalWriteOnly();
- _getStdioHandle(_stderr, 2);
+ _stderr = _getStdioOutputStream(2);
}
- return _stderr.outputStream;
+ return _stderr;
}
_getStdioHandle(Socket socket, int num) native "Socket_GetStdioHandle";
+_getStdioHandleType(int num) native "File_GetStdioHandleType";
« no previous file with comments | « runtime/bin/socket_impl.dart ('k') | tests/standalone/src/DartStdIOPipeTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698