File tree 2 files changed +37
-0
lines changed
2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -165,6 +165,9 @@ impl Stdin {
165
165
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
166
166
impl Read for Stdin {
167
167
fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
168
+ // Flush stdout so that weird issues like a print!'d prompt not being
169
+ // shown until after the user hits enter.
170
+ drop ( stdout ( ) . flush ( ) ) ;
168
171
self . lock ( ) . read ( buf)
169
172
}
170
173
fn read_to_end ( & mut self , buf : & mut Vec < u8 > ) -> io:: Result < usize > {
Original file line number Diff line number Diff line change
1
+ use std:: env;
2
+ use std:: io;
3
+ use std:: io:: { Read , Write } ;
4
+ use std:: process:: { Command , Stdio } ;
5
+
6
+ fn main ( ) {
7
+ if env:: args ( ) . count ( ) > 1 && env:: args ( ) . nth ( 1 ) == Some ( "child" . to_string ( ) ) {
8
+ child ( )
9
+ } else {
10
+ let mut p = Command :: new ( env:: args ( ) . nth ( 0 ) . unwrap ( ) )
11
+ . arg ( "child" )
12
+ . stdin ( Stdio :: piped ( ) )
13
+ . stdout ( Stdio :: piped ( ) )
14
+ . stderr ( Stdio :: inherit ( ) )
15
+ . spawn ( ) . unwrap ( ) ;
16
+ {
17
+ let mut buf = [ 0 ; 1 ] ;
18
+ assert ! ( p. stdout. as_mut( ) . unwrap( ) . read( & mut buf) . unwrap( ) >= 1 ) ;
19
+ assert_eq ! ( buf[ 0 ] , b'>' ) ;
20
+ assert ! ( p. stdin. as_mut( ) . unwrap( ) . write( b"abcd\n " ) . unwrap( ) >= 1 ) ;
21
+ }
22
+ // FIXME: timeout and fail on timeout
23
+ assert ! ( p. wait( ) . unwrap( ) . success( ) ) ;
24
+ }
25
+ }
26
+
27
+ fn child ( ) {
28
+ let stdout = io:: stdout ( ) ;
29
+ let lstdout = stdout. lock ( ) ;
30
+ let mut stdin = io:: stdin ( ) ;
31
+ print ! ( ">" ) ;
32
+ let mut letter = [ 0 ; 1 ] ;
33
+ stdin. read ( & mut letter) . unwrap ( ) ;
34
+ }
You can’t perform that action at this time.
0 commit comments