1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[open3] only close streams if a block is passed

Ref: 5429deb075

The previous change totally borke `popen2e` in this usage:

```ruby
require 'open3'
stdin, stdout, process = Open3.popen2e("cat")
puts stdout.read
```
This commit is contained in:
Jean Boussier 2020-06-18 16:01:36 +02:00 committed by Aaron Patterson
parent 42b4234ba4
commit adbdf11f94
Notes: git 2020-06-19 02:00:49 +09:00
2 changed files with 17 additions and 4 deletions

View file

@ -207,10 +207,12 @@ module Open3
popen_run(cmd, opts, [in_r, out_w], [in_w, out_r], &block)
ensure
in_r.close
in_w.close
out_r.close
out_w.close
if block
in_r.close
in_w.close
out_r.close
out_w.close
end
end
module_function :popen2e

View file

@ -149,6 +149,17 @@ class TestOpen3 < Test::Unit::TestCase
}
end
def test_popen2e_noblock
i, o, t = Open3.popen2e(RUBY, '-e', 'STDOUT.print STDIN.read')
i.print "baz"
i.close
assert_equal("baz", o.read)
ensure
i.close
o.close
t.join
end
def test_capture3
o, e, s = Open3.capture3(RUBY, '-e', 'i=STDIN.read; print i+"o"; STDOUT.flush; STDERR.print i+"e"', :stdin_data=>"i")
assert_equal("io", o)