@@ -57,28 +57,40 @@ void process_create_windows(const char* cmd, const char* stdin_stream,
57
57
fclose (stdin_fp );
58
58
}
59
59
60
- // Open stdout file if provided
60
+ // Open stdout file if provided, otherwise use the null device
61
61
if (stdout_file ) {
62
62
hStdout = CreateFile (stdout_file , GENERIC_WRITE , 0 , & sa , CREATE_ALWAYS , FILE_ATTRIBUTE_NORMAL , NULL );
63
63
if (hStdout == INVALID_HANDLE_VALUE ) {
64
64
fprintf (stderr , "Failed to open stdout file\n" );
65
65
return ;
66
66
}
67
- si .hStdOutput = hStdout ;
68
- si .dwFlags |= STARTF_USESTDHANDLES ;
67
+ } else {
68
+ hStdout = CreateFile ("NUL" , GENERIC_WRITE , 0 , NULL , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL );
69
+ if (hStdout == INVALID_HANDLE_VALUE ) {
70
+ fprintf (stderr , "Failed to open null device for stdout\n" );
71
+ return ;
72
+ }
69
73
}
74
+ si .hStdOutput = hStdout ;
75
+ si .dwFlags |= STARTF_USESTDHANDLES ;
70
76
71
- // Open stderr file if provided
77
+ // Open stderr file if provided, otherwise use the null device
72
78
if (stderr_file ) {
73
79
hStderr = CreateFile (stderr_file , GENERIC_WRITE , 0 , & sa , CREATE_ALWAYS , FILE_ATTRIBUTE_NORMAL , NULL );
74
80
if (hStderr == INVALID_HANDLE_VALUE ) {
75
81
fprintf (stderr , "Failed to open stderr file\n" );
76
82
return ;
77
83
}
78
- si .hStdError = hStderr ;
79
- si .dwFlags |= STARTF_USESTDHANDLES ;
84
+ } else {
85
+ hStderr = CreateFile ("NUL" , GENERIC_WRITE , 0 , NULL , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL );
86
+ if (hStderr == INVALID_HANDLE_VALUE ) {
87
+ fprintf (stderr , "Failed to open null device for stderr\n" );
88
+ return ;
89
+ }
80
90
}
81
-
91
+ si .hStdError = hStderr ;
92
+ si .dwFlags |= STARTF_USESTDHANDLES ;
93
+
82
94
// Prepare the command line with redirected stdin
83
95
char full_cmd [4096 ];
84
96
if (stdin_file ) {
0 commit comments