From: krasimir Date: Fri, 18 Mar 2005 17:28:08 +0000 (+0000) Subject: [project @ 2005-03-18 17:28:08 by krasimir] X-Git-Tag: arity-anal-branch-point~19 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=90f7b6cec2b034721ec0b7c015a23ec0aed63100;p=haskell-directory.git [project @ 2005-03-18 17:28:08 by krasimir] 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 --- diff --git a/cbits/runProcess.c b/cbits/runProcess.c index 82fa97e..b4a7557 100644 --- a/cbits/runProcess.c +++ b/cbits/runProcess.c @@ -401,15 +401,26 @@ runProcess (char *cmd, char *workingDirectory, void *environment, STARTUPINFO sInfo; PROCESS_INFORMATION pInfo; DWORD flags; + char buffer[256]; ZeroMemory(&sInfo, sizeof(sInfo)); - sInfo.cb = sizeof(sInfo); - sInfo.dwFlags = STARTF_USESTDHANDLES; + sInfo.cb = sizeof(sInfo); sInfo.hStdInput = (HANDLE) _get_osfhandle(fdStdInput); sInfo.hStdOutput= (HANDLE) _get_osfhandle(fdStdOutput); sInfo.hStdError = (HANDLE) _get_osfhandle(fdStdError); - if (sInfo.hStdOutput != GetStdHandle(STD_OUTPUT_HANDLE) && + if (sInfo.hStdInput == INVALID_HANDLE_VALUE) + sInfo.hStdInput = NULL; + if (sInfo.hStdOutput == INVALID_HANDLE_VALUE) + sInfo.hStdOutput = NULL; + if (sInfo.hStdError == INVALID_HANDLE_VALUE) + sInfo.hStdError = NULL; + + if (sInfo.hStdInput || sInfo.hStdOutput || sInfo.hStdError) + sInfo.dwFlags = STARTF_USESTDHANDLES; + + if (sInfo.hStdInput != GetStdHandle(STD_INPUT_HANDLE) && + sInfo.hStdOutput != GetStdHandle(STD_OUTPUT_HANDLE) && sInfo.hStdError != GetStdHandle(STD_ERROR_HANDLE)) flags = CREATE_NO_WINDOW; // Run without console window only when both output and error are redirected else