HACK: The redirection of standard handles under Windows is a little bit tricky
because we have to take in account that the application can be GUI.
The commit affects only Windows GUI applications.
MERGE TO STABLE
STARTUPINFO sInfo;\r
PROCESS_INFORMATION pInfo;\r
DWORD flags;\r
STARTUPINFO sInfo;\r
PROCESS_INFORMATION pInfo;\r
DWORD flags;\r
\r
ZeroMemory(&sInfo, sizeof(sInfo));\r
\r
ZeroMemory(&sInfo, sizeof(sInfo));\r
- sInfo.cb = sizeof(sInfo);\r
- sInfo.dwFlags = STARTF_USESTDHANDLES;\r
+ sInfo.cb = sizeof(sInfo); \r
sInfo.hStdInput = (HANDLE) _get_osfhandle(fdStdInput);\r
sInfo.hStdOutput= (HANDLE) _get_osfhandle(fdStdOutput);\r
sInfo.hStdError = (HANDLE) _get_osfhandle(fdStdError);\r
\r
sInfo.hStdInput = (HANDLE) _get_osfhandle(fdStdInput);\r
sInfo.hStdOutput= (HANDLE) _get_osfhandle(fdStdOutput);\r
sInfo.hStdError = (HANDLE) _get_osfhandle(fdStdError);\r
\r
- if (sInfo.hStdOutput != GetStdHandle(STD_OUTPUT_HANDLE) &&\r
+ if (sInfo.hStdInput == INVALID_HANDLE_VALUE)\r
+ sInfo.hStdInput = NULL;\r
+ if (sInfo.hStdOutput == INVALID_HANDLE_VALUE)\r
+ sInfo.hStdOutput = NULL;\r
+ if (sInfo.hStdError == INVALID_HANDLE_VALUE)\r
+ sInfo.hStdError = NULL;\r
+\r
+ if (sInfo.hStdInput || sInfo.hStdOutput || sInfo.hStdError)\r
+ sInfo.dwFlags = STARTF_USESTDHANDLES;\r
+\r
+ if (sInfo.hStdInput != GetStdHandle(STD_INPUT_HANDLE) &&\r
+ sInfo.hStdOutput != GetStdHandle(STD_OUTPUT_HANDLE) &&\r
sInfo.hStdError != GetStdHandle(STD_ERROR_HANDLE))\r
flags = CREATE_NO_WINDOW; // Run without console window only when both output and error are redirected\r
else\r
sInfo.hStdError != GetStdHandle(STD_ERROR_HANDLE))\r
flags = CREATE_NO_WINDOW; // Run without console window only when both output and error are redirected\r
else\r