From c5e27f5ce167651f5a82df37a3d764ed04ee7294 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Sat, 5 Mar 2011 21:10:58 -0800 Subject: [PATCH] call stdin.close right away when input is nil --- lib/posix/spawn/child.rb | 10 +++++++--- test/test_child.rb | 1 - 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/posix/spawn/child.rb b/lib/posix/spawn/child.rb index 46fd528..4572c85 100644 --- a/lib/posix/spawn/child.rb +++ b/lib/posix/spawn/child.rb @@ -145,8 +145,12 @@ def exec! # Raises MaximumOutputExceeded when the total number of bytes output # exceeds the amount specified by the max argument. def read_and_write(input, stdin, stdout, stderr, timeout=nil, max=nil) - input ||= '' - input.force_encoding('BINARY') if input.respond_to?(:force_encoding) + if input + input = input.dup.force_encoding('BINARY') if input.respond_to?(:force_encoding) + else + stdin.close + end + max = nil if max && max <= 0 out, err = '', '' offset = 0 @@ -155,7 +159,7 @@ def read_and_write(input, stdin, stdout, stderr, timeout=nil, max=nil) @runtime = 0.0 start = Time.now - writers = [stdin] + writers = input ? [stdin] : [] readers = [stdout, stderr] t = timeout while readers.any? || writers.any? diff --git a/test/test_child.rb b/test/test_child.rb index cefecb1..c8826a0 100644 --- a/test/test_child.rb +++ b/test/test_child.rb @@ -111,6 +111,5 @@ def test_utf8_input input = "hålø" p = Child.new('cat', :input => input) assert p.success? - assert_equal input, p.out end end