From b32ca05cd422bc8faf3ce267d59b1421e8ca11ef Mon Sep 17 00:00:00 2001 From: RadAd Date: Mon, 27 May 2019 10:59:29 +1000 Subject: Some fixes for non conpty. --- ProcessUtils.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ProcessUtils.cpp b/ProcessUtils.cpp index 8b8aa45..4a44ae3 100644 --- a/ProcessUtils.cpp +++ b/ProcessUtils.cpp @@ -25,6 +25,8 @@ namespace { std::vector attrList; si.StartupInfo.cb = sizeof(si); + BOOL bInheritHandles = FALSE; + if (bUseConPty) { spd.hr = CreatePseudoConsole( @@ -81,11 +83,12 @@ namespace { si.StartupInfo.hStdOutput = hOutput; si.StartupInfo.hStdError = si.StartupInfo.hStdOutput; dwCreationFlags |= CREATE_NO_WINDOW; + bInheritHandles = TRUE; } TCHAR localcmd[MAX_PATH]; wcscpy_s(localcmd, cmd); - if (!CreateProcess(nullptr, localcmd, nullptr, nullptr, FALSE, dwCreationFlags, nullptr, nullptr, &si.StartupInfo, &spd.pi)) + if (!CreateProcess(nullptr, localcmd, nullptr, nullptr, bInheritHandles, dwCreationFlags, nullptr, nullptr, &si.StartupInfo, &spd.pi)) { spd.hr = HRESULT_FROM_WIN32(GetLastError()); CleanupSubProcess(&spd); @@ -102,18 +105,21 @@ SubProcessData CreateSubProcess(LPCTSTR cmd, COORD size, bool bUseConPty) { SubProcessData spd = {}; + SECURITY_ATTRIBUTES sa = {}; + sa.bInheritHandle = !bUseConPty; + HANDLE hReadPipeInput = NULL; HANDLE hWritePipeInput = NULL; - if (spd.hr == S_OK && !CreatePipe(&hReadPipeInput, &hWritePipeInput, nullptr, 0)) + if (spd.hr == S_OK && !CreatePipe(&hReadPipeInput, &hWritePipeInput, &sa, 0)) spd.hr = HRESULT_FROM_WIN32(GetLastError()); HANDLE hWritePipeOutput = NULL; HANDLE hReadPipeOutput = NULL; - if (spd.hr == S_OK && !CreatePipe(&hReadPipeOutput, &hWritePipeOutput, nullptr, 0)) + if (spd.hr == S_OK && !CreatePipe(&hReadPipeOutput, &hWritePipeOutput, &sa, 0)) spd.hr = HRESULT_FROM_WIN32(GetLastError()); if (spd.hr == S_OK) - spd = CreateSubProcess(cmd, size, hReadPipeInput, hWritePipeOutput, true); + spd = CreateSubProcess(cmd, size, hReadPipeInput, hWritePipeOutput, bUseConPty); if (spd.hr == S_OK) { -- cgit v1.2.3