Skip to content

Commit

Permalink
call stdin.close right away when input is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Mar 6, 2011
1 parent 8849432 commit c5e27f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/posix/spawn/child.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?
Expand Down
1 change: 0 additions & 1 deletion test/test_child.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c5e27f5

Please sign in to comment.