From ffd61d4d5466ddceff2403d71e445688bb141e24 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Tue, 12 Sep 2023 02:01:12 +0100 Subject: [PATCH] [*] NT: AuProcess this is better --- Source/Processes/AuProcess.NT.cpp | 54 ++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/Source/Processes/AuProcess.NT.cpp b/Source/Processes/AuProcess.NT.cpp index 9dbd7e16..4120b1b2 100644 --- a/Source/Processes/AuProcess.NT.cpp +++ b/Source/Processes/AuProcess.NT.cpp @@ -295,14 +295,22 @@ namespace Aurora::Processes } else if (this->startup_.fwdOut == EStreamForward::eCurrentProcess) { - HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); + HANDLE hHandle = GetStdHandle(STD_OUTPUT_HANDLE); - if (handle != INVALID_HANDLE_VALUE && handle) + if (hHandle != INVALID_HANDLE_VALUE) { - SetHandleInformation(handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT); + HANDLE hTargetProcess = ::GetCurrentProcess(); - this->bDontRelOut_ = true; - this->pipeStdOutWrite_ = handle; + if (!::DuplicateHandle(hTargetProcess, + hHandle, + hTargetProcess, + &this->pipeStdOutWrite_, + GENERIC_READ | GENERIC_WRITE, + TRUE, + 0)) + { + return false; + } } } @@ -347,14 +355,22 @@ namespace Aurora::Processes } else if (this->startup_.fwdErr == EStreamForward::eCurrentProcess) { - HANDLE handle = GetStdHandle(STD_ERROR_HANDLE); + HANDLE hHandle = GetStdHandle(STD_ERROR_HANDLE); - if (handle != INVALID_HANDLE_VALUE && handle) + if (hHandle != INVALID_HANDLE_VALUE) { - SetHandleInformation(handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT); + HANDLE hTargetProcess = ::GetCurrentProcess(); - this->bDontRelErr_ = true; - this->pipeStdErrWrite_ = handle; + if (!::DuplicateHandle(hTargetProcess, + hHandle, + hTargetProcess, + &this->pipeStdErrWrite_, + GENERIC_READ | GENERIC_WRITE, + TRUE, + 0)) + { + return false; + } } } @@ -399,14 +415,22 @@ namespace Aurora::Processes } else if (this->startup_.fwdIn == EStreamForward::eCurrentProcess) { - HANDLE handle = GetStdHandle(STD_ERROR_HANDLE); + HANDLE hHandle = GetStdHandle(STD_INPUT_HANDLE); - if (handle != INVALID_HANDLE_VALUE && handle) + if (hHandle != INVALID_HANDLE_VALUE) { - SetHandleInformation(handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT); + HANDLE hTargetProcess = ::GetCurrentProcess(); - this->bDontRelIn_ = true; - this->pipeStdInRead_ = handle; + if (!::DuplicateHandle(hTargetProcess, + hHandle, + hTargetProcess, + &this->pipeStdInRead_, + GENERIC_READ, + TRUE, + 0)) + { + return false; + } } }