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