@@ -252,10 +252,6 @@ impl Command {
252
252
) -> io:: Result < ( Process , StdioPipes ) > {
253
253
let maybe_env = self . env . capture_if_changed ( ) ;
254
254
255
- let mut si = zeroed_startupinfo ( ) ;
256
- si. cb = mem:: size_of :: < c:: STARTUPINFO > ( ) as c:: DWORD ;
257
- si. dwFlags = c:: STARTF_USESTDHANDLES ;
258
-
259
255
let child_paths = if let Some ( env) = maybe_env. as_ref ( ) {
260
256
env. get ( & EnvKey :: new ( "PATH" ) ) . map ( |s| s. as_os_str ( ) )
261
257
} else {
@@ -314,9 +310,21 @@ impl Command {
314
310
let stdin = stdin. to_handle ( c:: STD_INPUT_HANDLE , & mut pipes. stdin ) ?;
315
311
let stdout = stdout. to_handle ( c:: STD_OUTPUT_HANDLE , & mut pipes. stdout ) ?;
316
312
let stderr = stderr. to_handle ( c:: STD_ERROR_HANDLE , & mut pipes. stderr ) ?;
317
- si. hStdInput = stdin. as_raw_handle ( ) ;
318
- si. hStdOutput = stdout. as_raw_handle ( ) ;
319
- si. hStdError = stderr. as_raw_handle ( ) ;
313
+
314
+ let mut si = zeroed_startupinfo ( ) ;
315
+ si. cb = mem:: size_of :: < c:: STARTUPINFO > ( ) as c:: DWORD ;
316
+
317
+ // If at least one of stdin, stdout or stderr are set (i.e. are non null)
318
+ // then set the `hStd` fields in `STARTUPINFO`.
319
+ // Otherwise skip this and allow the OS to apply its default behaviour.
320
+ // This provides more consistent behaviour between Win7 and Win8+.
321
+ let is_set = |stdio : & Handle | !stdio. as_raw_handle ( ) . is_null ( ) ;
322
+ if is_set ( & stderr) || is_set ( & stdout) || is_set ( & stdin) {
323
+ si. dwFlags |= c:: STARTF_USESTDHANDLES ;
324
+ si. hStdInput = stdin. as_raw_handle ( ) ;
325
+ si. hStdOutput = stdout. as_raw_handle ( ) ;
326
+ si. hStdError = stderr. as_raw_handle ( ) ;
327
+ }
320
328
321
329
unsafe {
322
330
cvt ( c:: CreateProcessW (
0 commit comments