diff --git a/std/process.d b/std/process.d index 9019780b4..ca6f46cb2 100644 --- a/std/process.d +++ b/std/process.d @@ -515,8 +515,6 @@ private Pid spawnProcessImpl(in char[] commandLine, // Startup info for CreateProcessW(). STARTUPINFO_W startinfo; startinfo.cb = startinfo.sizeof; - startinfo.dwFlags = STARTF_USESTDHANDLES; - static int getFD(ref File f) { return f.isOpen ? f.fileno : -1; } // Extract file descriptors and HANDLEs from the streams and make the @@ -525,8 +523,12 @@ private Pid spawnProcessImpl(in char[] commandLine, out int fileDescriptor, out HANDLE handle) { fileDescriptor = getFD(file); - if (fileDescriptor < 0) handle = GetStdHandle(stdHandle); - else handle = file.windowsHandle; + handle = null; + if (fileDescriptor >= 0) + handle = file.windowsHandle; + // Windows GUI applications have a fd but not a valid Windows HANDLE. + if (handle is null || handle == INVALID_HANDLE_VALUE) + handle = GetStdHandle(stdHandle); DWORD dwFlags; if (GetHandleInformation(handle, &dwFlags)) @@ -550,6 +552,11 @@ private Pid spawnProcessImpl(in char[] commandLine, prepareStream(stdout, STD_OUTPUT_HANDLE, "stdout", stdoutFD, startinfo.hStdOutput); prepareStream(stderr, STD_ERROR_HANDLE, "stderr", stderrFD, startinfo.hStdError ); + if ((startinfo.hStdInput != null && startinfo.hStdInput != INVALID_HANDLE_VALUE) + || (startinfo.hStdOutput != null && startinfo.hStdOutput != INVALID_HANDLE_VALUE) + || (startinfo.hStdError != null && startinfo.hStdError != INVALID_HANDLE_VALUE)) + startinfo.dwFlags = STARTF_USESTDHANDLES; + // Create process. PROCESS_INFORMATION pi; DWORD dwCreationFlags =