diff options
Diffstat (limited to 'src/zencore/process.cpp')
| -rw-r--r-- | src/zencore/process.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/zencore/process.cpp b/src/zencore/process.cpp index dcb8b2422..e7baa3f8e 100644 --- a/src/zencore/process.cpp +++ b/src/zencore/process.cpp @@ -277,6 +277,46 @@ CreateStdoutPipe(StdoutPipeHandles& OutPipe) ProcessHandle::ProcessHandle() = default; +ProcessHandle::ProcessHandle(int Pid) +{ + Initialize(Pid); +} + +#if ZEN_PLATFORM_WINDOWS +ProcessHandle::ProcessHandle(void* NativeHandle) +{ + Initialize(NativeHandle); +} +#endif + +ProcessHandle::ProcessHandle(ProcessHandle&& Other) noexcept +: m_ProcessHandle(Other.m_ProcessHandle) +, m_Pid(Other.m_Pid) +#if ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC +, m_ExitCode(Other.m_ExitCode) +#endif +{ + Other.m_ProcessHandle = nullptr; + Other.m_Pid = 0; +} + +ProcessHandle& +ProcessHandle::operator=(ProcessHandle&& Other) noexcept +{ + if (this != &Other) + { + Reset(); + m_ProcessHandle = Other.m_ProcessHandle; + m_Pid = Other.m_Pid; +#if ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC + m_ExitCode = Other.m_ExitCode; +#endif + Other.m_ProcessHandle = nullptr; + Other.m_Pid = 0; + } + return *this; +} + #if ZEN_PLATFORM_WINDOWS void ProcessHandle::Initialize(void* ProcessHandle) @@ -720,6 +760,10 @@ CreateProcNormal(const std::filesystem::path& Executable, std::string_view Comma } if (Options.Flags & CreateProcOptions::Flag_NoConsole) { + CreationFlags |= DETACHED_PROCESS; + } + if (Options.Flags & CreateProcOptions::Flag_NoWindow) + { CreationFlags |= CREATE_NO_WINDOW; } if (Options.Flags & CreateProcOptions::Flag_Windows_NewProcessGroup) @@ -930,6 +974,10 @@ CreateProcUnelevated(const std::filesystem::path& Executable, std::string_view C } if (Options.Flags & CreateProcOptions::Flag_NoConsole) { + CreateProcFlags |= DETACHED_PROCESS; + } + if (Options.Flags & CreateProcOptions::Flag_NoWindow) + { CreateProcFlags |= CREATE_NO_WINDOW; } if (AssignToJob) @@ -1070,6 +1118,11 @@ CreateProc(const std::filesystem::path& Executable, std::string_view CommandLine } } + if (Options.ProcessGroupId > 0) + { + setpgid(0, Options.ProcessGroupId); + } + for (const auto& [Key, Value] : Options.Environment) { setenv(Key.c_str(), Value.c_str(), 1); |