From 22acd46e30cb3e0c72c81dcaf6b78c83fb18aade Mon Sep 17 00:00:00 2001 From: Dmytro Bogovych Date: Mon, 3 Dec 2018 13:05:52 +0200 Subject: [PATCH] - more cleanups --- src/engine/helper/HL_Process.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/engine/helper/HL_Process.cpp b/src/engine/helper/HL_Process.cpp index 2f32999c..675d6ade 100644 --- a/src/engine/helper/HL_Process.cpp +++ b/src/engine/helper/HL_Process.cpp @@ -89,7 +89,7 @@ std::shared_ptr OsProcess::asyncExecCommand(const std::string& cmdl SECURITY_ATTRIBUTES saAttr = { sizeof(SECURITY_ATTRIBUTES), nullptr, FALSE }; saAttr.bInheritHandle = TRUE; //Pipe handles are inherited by child process. saAttr.lpSecurityDescriptor = nullptr; - + // Create a pipe to get results from child's stdout. if ( !CreatePipe(&hPipeRead, &hPipeWrite, &saAttr, 0) ) return std::shared_ptr(); @@ -107,6 +107,7 @@ std::shared_ptr OsProcess::asyncExecCommand(const std::string& cmdl char* cmdbuffer = (char*)_alloca(cmdline.size()+1); strcpy(cmdbuffer, StringHelper::replace(cmdline, "/", "\\").c_str()); + BOOL fSuccess = CreateProcessA( nullptr, cmdbuffer, nullptr, nullptr, TRUE, CREATE_NEW_CONSOLE, nullptr, nullptr, &si, &pi); if (! fSuccess) @@ -158,8 +159,20 @@ std::shared_ptr OsProcess::asyncExecCommand(const std::string& cmdl if (buf[0]) callback(StringHelper::trim(std::string(buf))); + char ctrlc = 3; + //if (finish_flag) + // ::WriteFile(hPipeWrite, &ctrlc, 1, nullptr, nullptr); + + // GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pi.dwProcessId); + CloseHandle( hPipeWrite ); CloseHandle( hPipeRead ); + if (finish_flag) + { + //GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0); + // Close underlying process + //TerminateProcess(pi.hProcess, 3); + } CloseHandle( pi.hProcess ); CloseHandle( pi.hThread );