From fd7a02f9600edb4a98498ceb23441a54257f462f Mon Sep 17 00:00:00 2001 From: glass Date: Thu, 7 Aug 2014 14:31:54 +0000 Subject: * 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 --- lib/open3.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'lib/open3.rb') 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] -- cgit v1.2.3