On windows only inherit handles if required for process output

This commit is contained in:
baldurk
2022-02-17 17:38:01 +00:00
parent 60e1f86571
commit a51b20369f
+8 -5
View File
@@ -488,6 +488,8 @@ static PROCESS_INFORMATION RunProcess(const rdcstr &app, const rdcstr &workingDi
wcscat_s(paramsAlloc, len, wcmd.c_str());
}
bool inheritHandles = false;
HANDLE hChildStdOutput_Wr = 0, hChildStdError_Wr = 0;
if(phChildStdOutput_Rd)
{
@@ -511,6 +513,9 @@ static PROCESS_INFORMATION RunProcess(const rdcstr &app, const rdcstr &workingDi
si.dwFlags |= STARTF_USESTDHANDLES;
si.hStdOutput = hChildStdOutput_Wr;
si.hStdError = hChildStdError_Wr;
// Need to inherit handles in CreateProcess for ReadFile to read stdout
inheritHandles = true;
}
// if it's a utility launch, hide the command prompt window from showing
@@ -540,11 +545,9 @@ static PROCESS_INFORMATION RunProcess(const rdcstr &app, const rdcstr &workingDi
}
}
BOOL retValue = CreateProcessW(NULL, paramsAlloc, &pSec, &tSec,
true, // Need to inherit handles for ReadFile to read stdout
CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT,
envString.empty() ? NULL : (void *)envString.data(),
workdir.c_str(), &si, &pi);
BOOL retValue = CreateProcessW(
NULL, paramsAlloc, &pSec, &tSec, inheritHandles, CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT,
envString.empty() ? NULL : (void *)envString.data(), workdir.c_str(), &si, &pi);
DWORD err = GetLastError();