mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
707ff7bfb7
commit
fd7a02f960
2 changed files with 16 additions and 8 deletions
|
@ -1,3 +1,7 @@
|
|||
Thu Aug 7 23:25:29 2014 Masaki Matsushita <glass.saga@gmail.com>
|
||||
|
||||
* lib/open3.rb: avoid unnecessary write if stdin_data is empty.
|
||||
|
||||
Thu Aug 7 21:42:49 2014 Masaki Suketa <masaki.suketa@nifty.ne.jp>
|
||||
|
||||
* ext/win32ole/win32ole_typelib.c (foletypelib_version): return
|
||||
|
|
20
lib/open3.rb
20
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]
|
||||
|
|
Loading…
Add table
Reference in a new issue