* 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
@ -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>
|
Thu Aug 7 21:42:49 2014 Masaki Suketa <masaki.suketa@nifty.ne.jp>
|
||||||
|
|
||||||
* ext/win32ole/win32ole_typelib.c (foletypelib_version): return
|
* ext/win32ole/win32ole_typelib.c (foletypelib_version): return
|
||||||
|
20
lib/open3.rb
20
lib/open3.rb
@ -296,16 +296,18 @@ module Open3
|
|||||||
# End
|
# End
|
||||||
# image, s = Open3.capture2("gnuplot", :stdin_data=>gnuplot_commands, :binmode=>true)
|
# 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|
|
popen2(*cmd, opts) {|i, o, t|
|
||||||
if binmode
|
if binmode
|
||||||
i.binmode
|
i.binmode
|
||||||
o.binmode
|
o.binmode
|
||||||
end
|
end
|
||||||
out_reader = Thread.new { o.read }
|
out_reader = Thread.new { o.read }
|
||||||
begin
|
if stdin_data
|
||||||
i.write stdin_data
|
begin
|
||||||
rescue Errno::EPIPE
|
i.write stdin_data
|
||||||
|
rescue Errno::EPIPE
|
||||||
|
end
|
||||||
end
|
end
|
||||||
i.close
|
i.close
|
||||||
[out_reader.value, t.value]
|
[out_reader.value, t.value]
|
||||||
@ -329,16 +331,18 @@ module Open3
|
|||||||
# # capture make log
|
# # capture make log
|
||||||
# make_log, s = Open3.capture2e("make")
|
# 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|
|
popen2e(*cmd, opts) {|i, oe, t|
|
||||||
if binmode
|
if binmode
|
||||||
i.binmode
|
i.binmode
|
||||||
oe.binmode
|
oe.binmode
|
||||||
end
|
end
|
||||||
outerr_reader = Thread.new { oe.read }
|
outerr_reader = Thread.new { oe.read }
|
||||||
begin
|
if stdin_data
|
||||||
i.write stdin_data
|
begin
|
||||||
rescue Errno::EPIPE
|
i.write stdin_data
|
||||||
|
rescue Errno::EPIPE
|
||||||
|
end
|
||||||
end
|
end
|
||||||
i.close
|
i.close
|
||||||
[outerr_reader.value, t.value]
|
[outerr_reader.value, t.value]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user