From 04b015a8e52ead4d8bb5f0eb486419c77e418a17 Mon Sep 17 00:00:00 2001 From: Haowen Liu <35328328+lunacd@users.noreply.github.com> Date: Tue, 22 Apr 2025 08:02:49 -0400 Subject: [PATCH] Get Windows return code in wait() (#109) Currently, wait() returns 0 on windows regardless of the actual return code of processes. --- subprocess.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/subprocess.hpp b/subprocess.hpp index c92f56a..1e8efaf 100755 --- a/subprocess.hpp +++ b/subprocess.hpp @@ -1411,7 +1411,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(pid());