diff options
author | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-08-07 14:31:54 +0000 |
---|---|---|
committer | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-08-07 14:31:54 +0000 |
commit | fd7a02f9600edb4a98498ceb23441a54257f462f (patch) | |
tree | fd2fe9b70a6597f9d70fff099223aa383c4147c8 /lib/open3.rb | |
parent | 707ff7bfb715d7caa7766041cea8bad6e8ca43a0 (diff) |
* lib/open3.rb: avoid unnecessary write if stdin_data is empty.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/open3.rb')
-rw-r--r-- | lib/open3.rb | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/open3.rb b/lib/open3.rb index 7595265a93..543be75a14 100644 --- a/lib/open3.rb +++ b/lib/open3.rb @@ -296,16 +296,18 @@ module Open3 # End # image, s = Open3.capture2("gnuplot", :stdin_data=>gnuplot_commands, :binmode=>true) # - def capture2(*cmd, stdin_data: '', binmode: false, **opts) + def capture2(*cmd, stdin_data: nil, binmode: false, **opts) popen2(*cmd, opts) {|i, o, t| if binmode i.binmode o.binmode end out_reader = Thread.new { o.read } - begin - i.write stdin_data - rescue Errno::EPIPE + if stdin_data + begin + i.write stdin_data + rescue Errno::EPIPE + end end i.close [out_reader.value, t.value] @@ -329,16 +331,18 @@ module Open3 # # capture make log # make_log, s = Open3.capture2e("make") # - def capture2e(*cmd, stdin_data: '', binmode: false, **opts) + def capture2e(*cmd, stdin_data: nil, binmode: false, **opts) popen2e(*cmd, opts) {|i, oe, t| if binmode i.binmode oe.binmode end outerr_reader = Thread.new { oe.read } - begin - i.write stdin_data - rescue Errno::EPIPE + if stdin_data + begin + i.write stdin_data + rescue Errno::EPIPE + end end i.close [outerr_reader.value, t.value] |