From 5aaa35421d709fb5deb5c0bcb718706826bb35d9 Mon Sep 17 00:00:00 2001 From: Songstats Audit Date: Sat, 29 Aug 2026 22:22:26 +0200 Subject: [PATCH 1/2] Honor to_io-only redirection wrappers --- lib/childprocess/process_spawn_process.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/childprocess/process_spawn_process.rb b/lib/childprocess/process_spawn_process.rb index 11bd3a6..14f1231 100644 --- a/lib/childprocess/process_spawn_process.rb +++ b/lib/childprocess/process_spawn_process.rb @@ -51,8 +51,8 @@ def launch_process options = {} - options[:out] = io.stdout ? io.stdout.fileno : File::NULL - options[:err] = io.stderr ? io.stderr.fileno : File::NULL + options[:out] = io.stdout ? fileno_for(io.stdout) : File::NULL + options[:err] = io.stderr ? fileno_for(io.stderr) : File::NULL if duplex? reader, writer = ::IO.pipe @@ -100,6 +100,10 @@ def set_exit_code(status) @exit_code = status.exitstatus || status.termsig end + def fileno_for(io) + io.respond_to?(:fileno) ? io.fileno : io.to_io.fileno + end + def send_term send_signal 'TERM' end From 882436142ee6f54232289a552c80e68be369e590 Mon Sep 17 00:00:00 2001 From: Oskar Eichler Date: Mon, 31 Aug 2026 16:41:57 +0700 Subject: [PATCH 2/2] Test to_io-only output wrappers --- spec/io_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spec/io_spec.rb b/spec/io_spec.rb index 0c16ee9..ad80fb7 100644 --- a/spec/io_spec.rb +++ b/spec/io_spec.rb @@ -60,6 +60,23 @@ end end + it "can redirect stdout through a to_io wrapper" do + process = echo + out = Tempfile.new("to-io-wrapper-spec") + wrapper = Object.new + wrapper.define_singleton_method(:to_io) { out.to_io } + + begin + process.io.stdout = wrapper + process.start + process.wait + + expect(rewind_and_read(out)).to eq "hello\n" + ensure + out.close + end + end + it "pumps all output" do process = echo