@@ -16,6 +16,23 @@ pub(crate) trait StdioExt: Sized {
16
16
fn stderr ( ) -> io:: Result < Box < dyn Handle > > ;
17
17
}
18
18
19
+ // The reason we have a separate Stdio type is to correctly facilitate redirects on Windows.
20
+ // To elaborate further, in POSIX, we can get a stdio handle by opening a specific fd {0,1,2}.
21
+ // On Windows however, we need to issue a syscall that's separate from standard Windows "open"
22
+ // to get a console handle, and this is GetStdHandle. This is exactly what Rust does and what
23
+ // is wrapped inside their Stdio object in the libstd. We wrap it here as well because of this
24
+ // nuance on Windows:
25
+ //
26
+ // The standard handles of a process may be redirected by a call to SetStdHandle, in which
27
+ // case GetStdHandle returns the redirected handle.
28
+ //
29
+ // The MSDN also says this however:
30
+ //
31
+ // If the standard handles have been redirected, you can specify the CONIN$ value in a call
32
+ // to the CreateFile function to get a handle to a console's input buffer. Similarly, you
33
+ // can specify the CONOUT$ value to get a handle to a console's active screen buffer.
34
+ //
35
+ // TODO it might worth re-investigating the suitability of this type on Windows.
19
36
#[ derive( Debug , Clone ) ]
20
37
#[ allow( dead_code) ]
21
38
pub ( crate ) enum Stdio {
@@ -75,11 +92,7 @@ impl Handle for Stdio {
75
92
// lock for the duration of the scope
76
93
let stdout = io:: stdout ( ) ;
77
94
let mut stdout = stdout. lock ( ) ;
78
- let nwritten = if self . is_tty ( ) {
79
- SandboxedTTYWriter :: new ( & mut stdout) . write_vectored ( & iovs) ?
80
- } else {
81
- stdout. write_vectored ( & iovs) ?
82
- } ;
95
+ let nwritten = SandboxedTTYWriter :: new ( & mut stdout) . write_vectored ( & iovs) ?;
83
96
stdout. flush ( ) ?;
84
97
nwritten
85
98
}
0 commit comments