@@ -17,7 +17,7 @@ use comm::{stream, SharedChan};
17
17
use libc:: { pid_t, c_int} ;
18
18
use libc;
19
19
use prelude:: * ;
20
- use rt:: io:: native :: process;
20
+ use rt:: io:: process;
21
21
use rt:: io;
22
22
use rt:: io:: extensions:: ReaderUtil ;
23
23
use task;
@@ -122,8 +122,24 @@ impl Process {
122
122
*/
123
123
pub fn new ( prog : & str , args : & [ ~str ] , options : ProcessOptions ) -> Process {
124
124
let ProcessOptions { env, dir, in_fd, out_fd, err_fd } = options;
125
- let inner = process:: Process :: new ( prog, args, env, dir,
126
- in_fd, out_fd, err_fd) ;
125
+ let env = env. as_ref ( ) . map ( |a| a. as_slice ( ) ) ;
126
+ let cwd = dir. as_ref ( ) . map ( |a| a. as_str ( ) . unwrap ( ) ) ;
127
+ fn rtify ( fd : Option < c_int > , input : bool ) -> process:: StdioContainer {
128
+ match fd {
129
+ Some ( fd) => process:: InheritFd ( fd) ,
130
+ None => process:: CreatePipe ( input, !input) ,
131
+ }
132
+ }
133
+ let rtio = [ rtify ( in_fd, true ) , rtify ( out_fd, false ) ,
134
+ rtify ( err_fd, false ) ] ;
135
+ let rtconfig = process:: ProcessConfig {
136
+ program : prog,
137
+ args : args,
138
+ env : env,
139
+ cwd : cwd,
140
+ io : rtio,
141
+ } ;
142
+ let inner = process:: Process :: new ( rtconfig) . unwrap ( ) ;
127
143
Process { inner : inner }
128
144
}
129
145
@@ -136,34 +152,40 @@ impl Process {
136
152
* Fails if there is no stdin available (it's already been removed by
137
153
* take_input)
138
154
*/
139
- pub fn input < ' a > ( & ' a mut self ) -> & ' a mut io:: Writer { self . inner . input ( ) }
155
+ pub fn input < ' a > ( & ' a mut self ) -> & ' a mut io:: Writer {
156
+ self . inner . io [ 0 ] . get_mut_ref ( ) as & mut io:: Writer
157
+ }
140
158
141
159
/**
142
160
* Returns an io::Reader that can be used to read from this Process's stdout.
143
161
*
144
162
* Fails if there is no stdout available (it's already been removed by
145
163
* take_output)
146
164
*/
147
- pub fn output < ' a > ( & ' a mut self ) -> & ' a mut io:: Reader { self . inner . output ( ) }
165
+ pub fn output < ' a > ( & ' a mut self ) -> & ' a mut io:: Reader {
166
+ self . inner . io [ 1 ] . get_mut_ref ( ) as & mut io:: Reader
167
+ }
148
168
149
169
/**
150
170
* Returns an io::Reader that can be used to read from this Process's stderr.
151
171
*
152
172
* Fails if there is no stderr available (it's already been removed by
153
173
* take_error)
154
174
*/
155
- pub fn error < ' a > ( & ' a mut self ) -> & ' a mut io:: Reader { self . inner . error ( ) }
175
+ pub fn error < ' a > ( & ' a mut self ) -> & ' a mut io:: Reader {
176
+ self . inner . io [ 2 ] . get_mut_ref ( ) as & mut io:: Reader
177
+ }
156
178
157
179
/**
158
180
* Closes the handle to the child process's stdin.
159
181
*/
160
182
pub fn close_input ( & mut self ) {
161
- self . inner . take_input ( ) ;
183
+ self . inner . io [ 0 ] . take ( ) ;
162
184
}
163
185
164
186
fn close_outputs ( & mut self ) {
165
- self . inner . take_output ( ) ;
166
- self . inner . take_error ( ) ;
187
+ self . inner . io [ 1 ] . take ( ) ;
188
+ self . inner . io [ 2 ] . take ( ) ;
167
189
}
168
190
169
191
/**
@@ -186,9 +208,9 @@ impl Process {
186
208
* were redirected to existing file descriptors.
187
209
*/
188
210
pub fn finish_with_output ( & mut self ) -> ProcessOutput {
189
- self . inner . take_input ( ) ; // close stdin
190
- let output = Cell :: new ( self . inner . take_output ( ) ) ;
191
- let error = Cell :: new ( self . inner . take_error ( ) ) ;
211
+ self . close_input ( ) ;
212
+ let output = Cell :: new ( self . inner . io [ 1 ] . take ( ) ) ;
213
+ let error = Cell :: new ( self . inner . io [ 2 ] . take ( ) ) ;
192
214
193
215
// Spawn two entire schedulers to read both stdout and sterr
194
216
// in parallel so we don't deadlock while blocking on one
0 commit comments