From 237a1c14776f67c14f7e14917198bbc41428fa28 Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Sun, 5 Apr 2015 05:32:08 +0000 Subject: [PATCH] fix Issue 14408 - std.process: Can't start interactive process from Windows GUI application --- std/process.d | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/std/process.d b/std/process.d index 763cb6849..86247f4ed 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 =