From 647630462f10cacc7a75da7c82ca7c6d33bbde4b Mon Sep 17 00:00:00 2001 From: Haowen Liu <35328328+lunacd@users.noreply.github.com> Date: Thu, 1 May 2025 22:07:21 +0100 Subject: [PATCH] subprocess: Get Windows return code in wait() Currently, wait() returns 0 on windows regardless of the actual return code of processes. Github-Pull: arun11299/cpp-subprocess#109 Rebased-From: 04b015a8e52ead4d8bb5f0eb486419c77e418a17 --- src/util/subprocess.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/util/subprocess.h b/src/util/subprocess.h index 086a4553619..ba274dfb471 100644 --- a/src/util/subprocess.h +++ b/src/util/subprocess.h @@ -1043,7 +1043,12 @@ inline int Popen::wait() noexcept(false) #ifdef __USING_WINDOWS__ int ret = WaitForSingleObject(process_handle_, INFINITE); - return 0; + DWORD dretcode_; + + if (FALSE == GetExitCodeProcess(process_handle_, &dretcode_)) + throw OSError("Failed during call to GetExitCodeProcess", 0); + + return (int)dretcode_; #else int ret, status; std::tie(ret, status) = util::wait_for_child_exit(child_pid_);