@@ -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" ) ]
@@ -70,6 +67,10 @@ pub struct Child {
70
67
pub stderr : Option < ChildStderr > ,
71
68
}
72
69
70
+ impl AsInner < imp:: Process > for Child {
71
+ fn as_inner ( & self ) -> & imp:: Process { & self . handle }
72
+ }
73
+
73
74
/// A handle to a child procesess's stdin
74
75
#[ stable( feature = "process" , since = "1.0.0" ) ]
75
76
pub struct ChildStdin {
@@ -87,6 +88,10 @@ impl Write for ChildStdin {
87
88
}
88
89
}
89
90
91
+ impl AsInner < AnonPipe > for ChildStdin {
92
+ fn as_inner ( & self ) -> & AnonPipe { & self . inner }
93
+ }
94
+
90
95
/// A handle to a child procesess's stdout
91
96
#[ stable( feature = "process" , since = "1.0.0" ) ]
92
97
pub struct ChildStdout {
@@ -100,6 +105,10 @@ impl Read for ChildStdout {
100
105
}
101
106
}
102
107
108
+ impl AsInner < AnonPipe > for ChildStdout {
109
+ fn as_inner ( & self ) -> & AnonPipe { & self . inner }
110
+ }
111
+
103
112
/// A handle to a child procesess's stderr
104
113
#[ stable( feature = "process" , since = "1.0.0" ) ]
105
114
pub struct ChildStderr {
@@ -113,6 +122,10 @@ impl Read for ChildStderr {
113
122
}
114
123
}
115
124
125
+ impl AsInner < AnonPipe > for ChildStderr {
126
+ fn as_inner ( & self ) -> & AnonPipe { & self . inner }
127
+ }
128
+
116
129
/// The `Command` type acts as a process builder, providing fine-grained control
117
130
/// over how a new process should be spawned. A default configuration can be
118
131
/// generated using `Command::new(program)`, where `program` gives a path to the
@@ -131,12 +144,12 @@ impl Read for ChildStderr {
131
144
/// ```
132
145
#[ stable( feature = "process" , since = "1.0.0" ) ]
133
146
pub struct Command {
134
- inner : CommandImp ,
147
+ inner : imp :: Command ,
135
148
136
149
// Details explained in the builder methods
137
- stdin : Option < StdioImp > ,
138
- stdout : Option < StdioImp > ,
139
- stderr : Option < StdioImp > ,
150
+ stdin : Option < Stdio > ,
151
+ stdout : Option < Stdio > ,
152
+ stderr : Option < Stdio > ,
140
153
}
141
154
142
155
impl Command {
@@ -153,7 +166,7 @@ impl Command {
153
166
#[ stable( feature = "process" , since = "1.0.0" ) ]
154
167
pub fn new < S : AsRef < OsStr > > ( program : S ) -> Command {
155
168
Command {
156
- inner : CommandImp :: new ( program. as_ref ( ) ) ,
169
+ inner : imp :: Command :: new ( program. as_ref ( ) ) ,
157
170
stdin : None ,
158
171
stdout : None ,
159
172
stderr : None ,
@@ -210,25 +223,26 @@ impl Command {
210
223
/// Configuration for the child process's stdin handle (file descriptor 0).
211
224
#[ stable( feature = "process" , since = "1.0.0" ) ]
212
225
pub fn stdin ( & mut self , cfg : Stdio ) -> & mut Command {
213
- self . stdin = Some ( cfg. 0 ) ;
226
+ self . stdin = Some ( cfg) ;
214
227
self
215
228
}
216
229
217
230
/// Configuration for the child process's stdout handle (file descriptor 1).
218
231
#[ stable( feature = "process" , since = "1.0.0" ) ]
219
232
pub fn stdout ( & mut self , cfg : Stdio ) -> & mut Command {
220
- self . stdout = Some ( cfg. 0 ) ;
233
+ self . stdout = Some ( cfg) ;
221
234
self
222
235
}
223
236
224
237
/// Configuration for the child process's stderr handle (file descriptor 2).
225
238
#[ stable( feature = "process" , since = "1.0.0" ) ]
226
239
pub fn stderr ( & mut self , cfg : Stdio ) -> & mut Command {
227
- self . stderr = Some ( cfg. 0 ) ;
240
+ self . stderr = Some ( cfg) ;
228
241
self
229
242
}
230
243
231
244
fn spawn_inner ( & self , default_io : StdioImp ) -> io:: Result < Child > {
245
+ let default_io = Stdio ( default_io) ;
232
246
let ( their_stdin, our_stdin) = try!(
233
247
setup_io ( self . stdin . as_ref ( ) . unwrap_or ( & default_io) , true )
234
248
) ;
@@ -239,7 +253,8 @@ impl Command {
239
253
setup_io ( self . stderr . as_ref ( ) . unwrap_or ( & default_io) , false )
240
254
) ;
241
255
242
- match ProcessImp :: spawn ( & self . inner , their_stdin, their_stdout, their_stderr) {
256
+ match imp:: Process :: spawn ( & self . inner , their_stdin, their_stdout,
257
+ their_stderr) {
243
258
Err ( e) => Err ( e) ,
244
259
Ok ( handle) => Ok ( Child {
245
260
handle : handle,
@@ -256,7 +271,7 @@ impl Command {
256
271
/// By default, stdin, stdout and stderr are inherited by the parent.
257
272
#[ stable( feature = "process" , since = "1.0.0" ) ]
258
273
pub fn spawn ( & mut self ) -> io:: Result < Child > {
259
- self . spawn_inner ( StdioImp :: Inherit )
274
+ self . spawn_inner ( StdioImp :: Raw ( imp :: Stdio :: Inherit ) )
260
275
}
261
276
262
277
/// Executes the command as a child process, waiting for it to finish and
@@ -279,7 +294,7 @@ impl Command {
279
294
/// ```
280
295
#[ stable( feature = "process" , since = "1.0.0" ) ]
281
296
pub fn output ( & mut self ) -> io:: Result < Output > {
282
- self . spawn_inner ( StdioImp :: Piped ) . and_then ( |p| p. wait_with_output ( ) )
297
+ self . spawn_inner ( StdioImp :: MakePipe ) . and_then ( |p| p. wait_with_output ( ) )
283
298
}
284
299
285
300
/// Executes a command as a child process, waiting for it to finish and
@@ -318,29 +333,27 @@ impl fmt::Debug for Command {
318
333
}
319
334
}
320
335
321
- impl AsInner < CommandImp > for Command {
322
- fn as_inner ( & self ) -> & CommandImp { & self . inner }
336
+ impl AsInner < imp :: Command > for Command {
337
+ fn as_inner ( & self ) -> & imp :: Command { & self . inner }
323
338
}
324
339
325
- impl AsInnerMut < CommandImp > for Command {
326
- fn as_inner_mut ( & mut self ) -> & mut CommandImp { & mut self . inner }
340
+ impl AsInnerMut < imp :: Command > for Command {
341
+ fn as_inner_mut ( & mut self ) -> & mut imp :: Command { & mut self . inner }
327
342
}
328
343
329
- fn setup_io ( io : & StdioImp , readable : bool )
330
- -> io:: Result < ( StdioImp2 , Option < AnonPipe > ) >
344
+ fn setup_io ( io : & Stdio , readable : bool )
345
+ -> io:: Result < ( imp :: Stdio , Option < AnonPipe > ) >
331
346
{
332
- use self :: StdioImp :: * ;
333
- Ok ( match * io {
334
- Null => ( StdioImp2 :: None , None ) ,
335
- Inherit => ( StdioImp2 :: Inherit , None ) ,
336
- Piped => {
347
+ Ok ( match io. 0 {
348
+ StdioImp :: MakePipe => {
337
349
let ( reader, writer) = try!( pipe:: anon_pipe ( ) ) ;
338
350
if readable {
339
- ( StdioImp2 :: Piped ( reader) , Some ( writer) )
351
+ ( imp :: Stdio :: Piped ( reader) , Some ( writer) )
340
352
} else {
341
- ( StdioImp2 :: Piped ( writer) , Some ( reader) )
353
+ ( imp :: Stdio :: Piped ( writer) , Some ( reader) )
342
354
}
343
355
}
356
+ StdioImp :: Raw ( ref raw) => ( raw. clone_if_copy ( ) , None ) ,
344
357
} )
345
358
}
346
359
@@ -364,32 +377,36 @@ pub struct Output {
364
377
pub struct Stdio ( StdioImp ) ;
365
378
366
379
// The internal enum for stdio setup; see below for descriptions.
367
- #[ derive( Clone ) ]
368
380
enum StdioImp {
369
- Piped ,
370
- Inherit ,
371
- Null ,
381
+ MakePipe ,
382
+ Raw ( imp:: Stdio ) ,
372
383
}
373
384
374
385
impl Stdio {
375
386
/// A new pipe should be arranged to connect the parent and child processes.
376
387
#[ stable( feature = "process" , since = "1.0.0" ) ]
377
- pub fn piped ( ) -> Stdio { Stdio ( StdioImp :: Piped ) }
388
+ pub fn piped ( ) -> Stdio { Stdio ( StdioImp :: MakePipe ) }
378
389
379
390
/// The child inherits from the corresponding parent descriptor.
380
391
#[ stable( feature = "process" , since = "1.0.0" ) ]
381
- pub fn inherit ( ) -> Stdio { Stdio ( StdioImp :: Inherit ) }
392
+ pub fn inherit ( ) -> Stdio { Stdio ( StdioImp :: Raw ( imp :: Stdio :: Inherit ) ) }
382
393
383
394
/// This stream will be ignored. This is the equivalent of attaching the
384
395
/// stream to `/dev/null`
385
396
#[ stable( feature = "process" , since = "1.0.0" ) ]
386
- pub fn null ( ) -> Stdio { Stdio ( StdioImp :: Null ) }
397
+ pub fn null ( ) -> Stdio { Stdio ( StdioImp :: Raw ( imp:: Stdio :: None ) ) }
398
+ }
399
+
400
+ impl FromInner < imp:: Stdio > for Stdio {
401
+ fn from_inner ( inner : imp:: Stdio ) -> Stdio {
402
+ Stdio ( StdioImp :: Raw ( inner) )
403
+ }
387
404
}
388
405
389
406
/// Describes the result of a process after it has terminated.
390
407
#[ derive( PartialEq , Eq , Clone , Copy , Debug ) ]
391
408
#[ stable( feature = "process" , since = "1.0.0" ) ]
392
- pub struct ExitStatus ( ExitStatusImp ) ;
409
+ pub struct ExitStatus ( imp :: ExitStatus ) ;
393
410
394
411
impl ExitStatus {
395
412
/// Was termination successful? Signal termination not considered a success,
@@ -410,8 +427,8 @@ impl ExitStatus {
410
427
}
411
428
}
412
429
413
- impl AsInner < ExitStatusImp > for ExitStatus {
414
- fn as_inner ( & self ) -> & ExitStatusImp { & self . 0 }
430
+ impl AsInner < imp :: ExitStatus > for ExitStatus {
431
+ fn as_inner ( & self ) -> & imp :: ExitStatus { & self . 0 }
415
432
}
416
433
417
434
#[ stable( feature = "process" , since = "1.0.0" ) ]
0 commit comments