@@ -22,11 +22,8 @@ use io::{self, Error, ErrorKind};
22
22
use path;
23
23
use sync:: mpsc:: { channel, Receiver } ;
24
24
use sys:: pipe:: { self , AnonPipe } ;
25
- use sys:: process:: Command as CommandImp ;
26
- use sys:: process:: Process as ProcessImp ;
27
- use sys:: process:: ExitStatus as ExitStatusImp ;
28
- use sys:: process:: Stdio as StdioImp2 ;
29
- use sys_common:: { AsInner , AsInnerMut } ;
25
+ use sys:: process as imp;
26
+ use sys_common:: { AsInner , AsInnerMut , FromInner } ;
30
27
use thread;
31
28
32
29
/// Representation of a running or exited child process.
@@ -52,10 +49,10 @@ use thread;
52
49
/// ```
53
50
#[ stable( feature = "process" , since = "1.0.0" ) ]
54
51
pub struct Child {
55
- handle : ProcessImp ,
52
+ handle : imp :: Process ,
56
53
57
54
/// None until wait() or wait_with_output() is called.
58
- status : Option < ExitStatusImp > ,
55
+ status : Option < imp :: ExitStatus > ,
59
56
60
57
/// The handle for writing to the child's stdin, if it has been captured
61
58
#[ stable( feature = "process" , since = "1.0.0" ) ]
@@ -87,6 +84,10 @@ impl Write for ChildStdin {
87
84
}
88
85
}
89
86
87
+ impl AsInner < AnonPipe > for ChildStdin {
88
+ fn as_inner ( & self ) -> & AnonPipe { & self . inner }
89
+ }
90
+
90
91
/// A handle to a child procesess's stdout
91
92
#[ stable( feature = "process" , since = "1.0.0" ) ]
92
93
pub struct ChildStdout {
@@ -100,6 +101,10 @@ impl Read for ChildStdout {
100
101
}
101
102
}
102
103
104
+ impl AsInner < AnonPipe > for ChildStdout {
105
+ fn as_inner ( & self ) -> & AnonPipe { & self . inner }
106
+ }
107
+
103
108
/// A handle to a child procesess's stderr
104
109
#[ stable( feature = "process" , since = "1.0.0" ) ]
105
110
pub struct ChildStderr {
@@ -113,6 +118,10 @@ impl Read for ChildStderr {
113
118
}
114
119
}
115
120
121
+ impl AsInner < AnonPipe > for ChildStderr {
122
+ fn as_inner ( & self ) -> & AnonPipe { & self . inner }
123
+ }
124
+
116
125
/// The `Command` type acts as a process builder, providing fine-grained control
117
126
/// over how a new process should be spawned. A default configuration can be
118
127
/// generated using `Command::new(program)`, where `program` gives a path to the
@@ -131,12 +140,12 @@ impl Read for ChildStderr {
131
140
/// ```
132
141
#[ stable( feature = "process" , since = "1.0.0" ) ]
133
142
pub struct Command {
134
- inner : CommandImp ,
143
+ inner : imp :: Command ,
135
144
136
145
// Details explained in the builder methods
137
- stdin : Option < StdioImp > ,
138
- stdout : Option < StdioImp > ,
139
- stderr : Option < StdioImp > ,
146
+ stdin : Option < Stdio > ,
147
+ stdout : Option < Stdio > ,
148
+ stderr : Option < Stdio > ,
140
149
}
141
150
142
151
impl Command {
@@ -153,7 +162,7 @@ impl Command {
153
162
#[ stable( feature = "process" , since = "1.0.0" ) ]
154
163
pub fn new < S : AsRef < OsStr > > ( program : S ) -> Command {
155
164
Command {
156
- inner : CommandImp :: new ( program. as_ref ( ) ) ,
165
+ inner : imp :: Command :: new ( program. as_ref ( ) ) ,
157
166
stdin : None ,
158
167
stdout : None ,
159
168
stderr : None ,
@@ -210,25 +219,26 @@ impl Command {
210
219
/// Configuration for the child process's stdin handle (file descriptor 0).
211
220
#[ stable( feature = "process" , since = "1.0.0" ) ]
212
221
pub fn stdin ( & mut self , cfg : Stdio ) -> & mut Command {
213
- self . stdin = Some ( cfg. 0 ) ;
222
+ self . stdin = Some ( cfg) ;
214
223
self
215
224
}
216
225
217
226
/// Configuration for the child process's stdout handle (file descriptor 1).
218
227
#[ stable( feature = "process" , since = "1.0.0" ) ]
219
228
pub fn stdout ( & mut self , cfg : Stdio ) -> & mut Command {
220
- self . stdout = Some ( cfg. 0 ) ;
229
+ self . stdout = Some ( cfg) ;
221
230
self
222
231
}
223
232
224
233
/// Configuration for the child process's stderr handle (file descriptor 2).
225
234
#[ stable( feature = "process" , since = "1.0.0" ) ]
226
235
pub fn stderr ( & mut self , cfg : Stdio ) -> & mut Command {
227
- self . stderr = Some ( cfg. 0 ) ;
236
+ self . stderr = Some ( cfg) ;
228
237
self
229
238
}
230
239
231
240
fn spawn_inner ( & self , default_io : StdioImp ) -> io:: Result < Child > {
241
+ let default_io = Stdio ( default_io) ;
232
242
let ( their_stdin, our_stdin) = try!(
233
243
setup_io ( self . stdin . as_ref ( ) . unwrap_or ( & default_io) , true )
234
244
) ;
@@ -239,7 +249,8 @@ impl Command {
239
249
setup_io ( self . stderr . as_ref ( ) . unwrap_or ( & default_io) , false )
240
250
) ;
241
251
242
- match ProcessImp :: spawn ( & self . inner , their_stdin, their_stdout, their_stderr) {
252
+ match imp:: Process :: spawn ( & self . inner , their_stdin, their_stdout,
253
+ their_stderr) {
243
254
Err ( e) => Err ( e) ,
244
255
Ok ( handle) => Ok ( Child {
245
256
handle : handle,
@@ -256,7 +267,7 @@ impl Command {
256
267
/// By default, stdin, stdout and stderr are inherited by the parent.
257
268
#[ stable( feature = "process" , since = "1.0.0" ) ]
258
269
pub fn spawn ( & mut self ) -> io:: Result < Child > {
259
- self . spawn_inner ( StdioImp :: Inherit )
270
+ self . spawn_inner ( StdioImp :: Raw ( imp :: Stdio :: Inherit ) )
260
271
}
261
272
262
273
/// Executes the command as a child process, waiting for it to finish and
@@ -279,7 +290,7 @@ impl Command {
279
290
/// ```
280
291
#[ stable( feature = "process" , since = "1.0.0" ) ]
281
292
pub fn output ( & mut self ) -> io:: Result < Output > {
282
- self . spawn_inner ( StdioImp :: Piped ) . and_then ( |p| p. wait_with_output ( ) )
293
+ self . spawn_inner ( StdioImp :: MakePipe ) . and_then ( |p| p. wait_with_output ( ) )
283
294
}
284
295
285
296
/// Executes a command as a child process, waiting for it to finish and
@@ -318,29 +329,27 @@ impl fmt::Debug for Command {
318
329
}
319
330
}
320
331
321
- impl AsInner < CommandImp > for Command {
322
- fn as_inner ( & self ) -> & CommandImp { & self . inner }
332
+ impl AsInner < imp :: Command > for Command {
333
+ fn as_inner ( & self ) -> & imp :: Command { & self . inner }
323
334
}
324
335
325
- impl AsInnerMut < CommandImp > for Command {
326
- fn as_inner_mut ( & mut self ) -> & mut CommandImp { & mut self . inner }
336
+ impl AsInnerMut < imp :: Command > for Command {
337
+ fn as_inner_mut ( & mut self ) -> & mut imp :: Command { & mut self . inner }
327
338
}
328
339
329
- fn setup_io ( io : & StdioImp , readable : bool )
330
- -> io:: Result < ( StdioImp2 , Option < AnonPipe > ) >
340
+ fn setup_io ( io : & Stdio , readable : bool )
341
+ -> io:: Result < ( imp :: Stdio , Option < AnonPipe > ) >
331
342
{
332
- use self :: StdioImp :: * ;
333
- Ok ( match * io {
334
- Null => ( StdioImp2 :: None , None ) ,
335
- Inherit => ( StdioImp2 :: Inherit , None ) ,
336
- Piped => {
343
+ Ok ( match io. 0 {
344
+ StdioImp :: MakePipe => {
337
345
let ( reader, writer) = try!( pipe:: anon_pipe ( ) ) ;
338
346
if readable {
339
- ( StdioImp2 :: Piped ( reader) , Some ( writer) )
347
+ ( imp :: Stdio :: Piped ( reader) , Some ( writer) )
340
348
} else {
341
- ( StdioImp2 :: Piped ( writer) , Some ( reader) )
349
+ ( imp :: Stdio :: Piped ( writer) , Some ( reader) )
342
350
}
343
351
}
352
+ StdioImp :: Raw ( ref raw) => ( raw. clone_if_copy ( ) , None ) ,
344
353
} )
345
354
}
346
355
@@ -364,32 +373,36 @@ pub struct Output {
364
373
pub struct Stdio ( StdioImp ) ;
365
374
366
375
// The internal enum for stdio setup; see below for descriptions.
367
- #[ derive( Clone ) ]
368
376
enum StdioImp {
369
- Piped ,
370
- Inherit ,
371
- Null ,
377
+ MakePipe ,
378
+ Raw ( imp:: Stdio ) ,
372
379
}
373
380
374
381
impl Stdio {
375
382
/// A new pipe should be arranged to connect the parent and child processes.
376
383
#[ stable( feature = "process" , since = "1.0.0" ) ]
377
- pub fn piped ( ) -> Stdio { Stdio ( StdioImp :: Piped ) }
384
+ pub fn piped ( ) -> Stdio { Stdio ( StdioImp :: MakePipe ) }
378
385
379
386
/// The child inherits from the corresponding parent descriptor.
380
387
#[ stable( feature = "process" , since = "1.0.0" ) ]
381
- pub fn inherit ( ) -> Stdio { Stdio ( StdioImp :: Inherit ) }
388
+ pub fn inherit ( ) -> Stdio { Stdio ( StdioImp :: Raw ( imp :: Stdio :: Inherit ) ) }
382
389
383
390
/// This stream will be ignored. This is the equivalent of attaching the
384
391
/// stream to `/dev/null`
385
392
#[ stable( feature = "process" , since = "1.0.0" ) ]
386
- pub fn null ( ) -> Stdio { Stdio ( StdioImp :: Null ) }
393
+ pub fn null ( ) -> Stdio { Stdio ( StdioImp :: Raw ( imp:: Stdio :: None ) ) }
394
+ }
395
+
396
+ impl FromInner < imp:: Stdio > for Stdio {
397
+ fn from_inner ( inner : imp:: Stdio ) -> Stdio {
398
+ Stdio ( StdioImp :: Raw ( inner) )
399
+ }
387
400
}
388
401
389
402
/// Describes the result of a process after it has terminated.
390
403
#[ derive( PartialEq , Eq , Clone , Copy , Debug ) ]
391
404
#[ stable( feature = "process" , since = "1.0.0" ) ]
392
- pub struct ExitStatus ( ExitStatusImp ) ;
405
+ pub struct ExitStatus ( imp :: ExitStatus ) ;
393
406
394
407
impl ExitStatus {
395
408
/// Was termination successful? Signal termination not considered a success,
@@ -410,8 +423,8 @@ impl ExitStatus {
410
423
}
411
424
}
412
425
413
- impl AsInner < ExitStatusImp > for ExitStatus {
414
- fn as_inner ( & self ) -> & ExitStatusImp { & self . 0 }
426
+ impl AsInner < imp :: ExitStatus > for ExitStatus {
427
+ fn as_inner ( & self ) -> & imp :: ExitStatus { & self . 0 }
415
428
}
416
429
417
430
#[ stable( feature = "process" , since = "1.0.0" ) ]
0 commit comments