From 4b230eb53552866c42159bb7c403bdf18cde2daa Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Sun, 30 Oct 2022 22:29:03 -0500 Subject: [PATCH] Hacky fix to reliably get exit status from W3DHub.command on windows --- lib/common.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/common.rb b/lib/common.rb index 3a4f856..fcd2166 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -42,19 +42,25 @@ class W3DHub def self.command(command, &block) if windows? - stdout_read, stdout_write = IO.pipe + stdout_read, stdout_write = IO.pipe if block - process_info = Process.create( + hash = { command_line: command, creation_flags: Process::DETACHED_PROCESS, process_inherit: true, thread_inherit: true, - inherit: true, - startup_info: { + close_handles: false, + inherit: true + } + + if block + hash[:startup_info] = { stdout: stdout_write, stderr: stdout_write } - ) + end + + process_info = Process.create(**hash) pid = process_info.process_id status = -1