@@ -40,7 +40,7 @@ pub struct ProcessBuilder {
4040 /// See [`ProcessBuilder::retry_with_argfile`] for more information.
4141 retry_with_argfile : bool ,
4242 /// Data to write to stdin.
43- stdin : Vec < u8 > ,
43+ stdin : Option < Vec < u8 > > ,
4444}
4545
4646impl fmt:: Display for ProcessBuilder {
@@ -82,7 +82,7 @@ impl ProcessBuilder {
8282 jobserver : None ,
8383 display_env_vars : false ,
8484 retry_with_argfile : false ,
85- stdin : Vec :: new ( ) ,
85+ stdin : None ,
8686 }
8787 }
8888
@@ -212,7 +212,7 @@ impl ProcessBuilder {
212212
213213 /// Sets a value that will be written to stdin of the process on launch.
214214 pub fn stdin < T : Into < Vec < u8 > > > ( & mut self , stdin : T ) -> & mut Self {
215- self . stdin = stdin. into ( ) ;
215+ self . stdin = Some ( stdin. into ( ) ) ;
216216 self
217217 }
218218
@@ -284,18 +284,22 @@ impl ProcessBuilder {
284284 fn _output ( & self ) -> io:: Result < Output > {
285285 if !debug_force_argfile ( self . retry_with_argfile ) {
286286 let mut cmd = self . build_command ( ) ;
287- match piped ( & mut cmd) . spawn ( ) {
287+ match piped ( & mut cmd, self . stdin . is_some ( ) ) . spawn ( ) {
288288 Err ( ref e) if self . should_retry_with_argfile ( e) => { }
289289 Err ( e) => return Err ( e) ,
290290 Ok ( mut child) => {
291- child. stdin . take ( ) . unwrap ( ) . write_all ( & self . stdin ) ?;
291+ if let Some ( stdin) = & self . stdin {
292+ child. stdin . take ( ) . unwrap ( ) . write_all ( stdin) ?;
293+ }
292294 return child. wait_with_output ( ) ;
293295 }
294296 }
295297 }
296298 let ( mut cmd, argfile) = self . build_command_with_argfile ( ) ?;
297- let mut child = piped ( & mut cmd) . spawn ( ) ?;
298- child. stdin . take ( ) . unwrap ( ) . write_all ( & self . stdin ) ?;
299+ let mut child = piped ( & mut cmd, self . stdin . is_some ( ) ) . spawn ( ) ?;
300+ if let Some ( stdin) = & self . stdin {
301+ child. stdin . take ( ) . unwrap ( ) . write_all ( stdin) ?;
302+ }
299303 let output = child. wait_with_output ( ) ;
300304 close_tempfile_and_log_error ( argfile) ;
301305 output
@@ -340,14 +344,14 @@ impl ProcessBuilder {
340344
341345 let spawn = |mut cmd| {
342346 if !debug_force_argfile ( self . retry_with_argfile ) {
343- match piped ( & mut cmd) . spawn ( ) {
347+ match piped ( & mut cmd, false ) . spawn ( ) {
344348 Err ( ref e) if self . should_retry_with_argfile ( e) => { }
345349 Err ( e) => return Err ( e) ,
346350 Ok ( child) => return Ok ( ( child, None ) ) ,
347351 }
348352 }
349353 let ( mut cmd, argfile) = self . build_command_with_argfile ( ) ?;
350- Ok ( ( piped ( & mut cmd) . spawn ( ) ?, Some ( argfile) ) )
354+ Ok ( ( piped ( & mut cmd, false ) . spawn ( ) ?, Some ( argfile) ) )
351355 } ;
352356
353357 let status = ( || {
@@ -541,11 +545,15 @@ fn debug_force_argfile(retry_enabled: bool) -> bool {
541545 cfg ! ( debug_assertions) && env:: var ( "__CARGO_TEST_FORCE_ARGFILE" ) . is_ok ( ) && retry_enabled
542546}
543547
544- /// Creates new pipes for stderr, stdout and stdin.
545- fn piped ( cmd : & mut Command ) -> & mut Command {
548+ /// Creates new pipes for stderr, stdout, and optionally stdin.
549+ fn piped ( cmd : & mut Command , pipe_stdin : bool ) -> & mut Command {
546550 cmd. stdout ( Stdio :: piped ( ) )
547551 . stderr ( Stdio :: piped ( ) )
548- . stdin ( Stdio :: piped ( ) )
552+ . stdin ( if pipe_stdin {
553+ Stdio :: piped ( )
554+ } else {
555+ Stdio :: null ( )
556+ } )
549557}
550558
551559fn close_tempfile_and_log_error ( file : NamedTempFile ) {
0 commit comments