From 7fe31126d121e810dd93641ae6582e9ab1dac16e Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Mon, 4 Oct 2021 11:59:26 -0400 Subject: Added ability to specify a working directory on opening a terminal. Released memory on calls using the ANSI creation function. --- ProcessUtils.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'ProcessUtils.cpp') diff --git a/ProcessUtils.cpp b/ProcessUtils.cpp index e3effc9..efafc00 100644 --- a/ProcessUtils.cpp +++ b/ProcessUtils.cpp @@ -16,7 +16,7 @@ namespace { spd->hPC = NULL; } - SubProcessData CreateSubProcess(LPCTSTR cmd, COORD size, HANDLE hInput, HANDLE hOutput, bool bUseConPty) + SubProcessData CreateSubProcess(LPCTSTR cmd, LPCTSTR wdir, COORD size, HANDLE hInput, HANDLE hOutput, bool bUseConPty) { SubProcessData spd = {}; @@ -87,8 +87,11 @@ namespace { } TCHAR localcmd[MAX_PATH]; + TCHAR localwdir[MAX_PATH]; _tcscpy_s(localcmd, cmd); - if (!CreateProcess(nullptr, localcmd, nullptr, nullptr, bInheritHandles, dwCreationFlags, nullptr, nullptr, &si.StartupInfo, &spd.pi)) + if(wdir != nullptr) + _tcscpy_s(localwdir, wdir); + if (!CreateProcess(nullptr, localcmd, nullptr, nullptr, bInheritHandles, dwCreationFlags, nullptr, wdir == nullptr ? nullptr : localwdir, &si.StartupInfo, &spd.pi)) { spd.hr = HRESULT_FROM_WIN32(GetLastError()); CleanupSubProcess(&spd); @@ -101,7 +104,7 @@ namespace { } } -SubProcessData CreateSubProcess(LPCTSTR cmd, COORD size, bool bUseConPty) +SubProcessData CreateSubProcess(LPCTSTR cmd, LPCTSTR wdir, COORD size, bool bUseConPty) { SubProcessData spd = {}; @@ -119,7 +122,7 @@ SubProcessData CreateSubProcess(LPCTSTR cmd, COORD size, bool bUseConPty) spd.hr = HRESULT_FROM_WIN32(GetLastError()); if (spd.hr == S_OK) - spd = CreateSubProcess(cmd, size, hReadPipeInput, hWritePipeOutput, bUseConPty); + spd = CreateSubProcess(cmd, wdir, size, hReadPipeInput, hWritePipeOutput, bUseConPty); if (spd.hr == S_OK) { -- cgit v1.2.3