* lib/open3.rb: receive arguments as keyword arguments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43582 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
05a4d176d6
commit
53dc9794f0
@ -1,3 +1,7 @@
|
|||||||
|
Fri Nov 8 18:35:31 2013 Masaki Matsushita <glass.saga@gmail.com>
|
||||||
|
|
||||||
|
* lib/open3.rb: receive arguments as keyword arguments.
|
||||||
|
|
||||||
Fri Nov 8 13:19:26 2013 Masaki Matsushita <glass.saga@gmail.com>
|
Fri Nov 8 13:19:26 2013 Masaki Matsushita <glass.saga@gmail.com>
|
||||||
|
|
||||||
* io.c (rb_io_open_with_args): use RARRAY_CONST_PTR().
|
* io.c (rb_io_open_with_args): use RARRAY_CONST_PTR().
|
||||||
|
97
lib/open3.rb
97
lib/open3.rb
@ -79,13 +79,7 @@ module Open3
|
|||||||
# If merged stdout and stderr output is not a problem, you can use Open3.popen2e.
|
# If merged stdout and stderr output is not a problem, you can use Open3.popen2e.
|
||||||
# If you really need stdout and stderr output as separate strings, you can consider Open3.capture3.
|
# If you really need stdout and stderr output as separate strings, you can consider Open3.capture3.
|
||||||
#
|
#
|
||||||
def popen3(*cmd, &block)
|
def popen3(*cmd, **opts, &block)
|
||||||
if Hash === cmd.last
|
|
||||||
opts = cmd.pop.dup
|
|
||||||
else
|
|
||||||
opts = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
in_r, in_w = IO.pipe
|
in_r, in_w = IO.pipe
|
||||||
opts[:in] = in_r
|
opts[:in] = in_r
|
||||||
in_w.sync = true
|
in_w.sync = true
|
||||||
@ -140,13 +134,7 @@ module Open3
|
|||||||
# p o.read #=> "*"
|
# p o.read #=> "*"
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
def popen2(*cmd, &block)
|
def popen2(*cmd, **opts, &block)
|
||||||
if Hash === cmd.last
|
|
||||||
opts = cmd.pop.dup
|
|
||||||
else
|
|
||||||
opts = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
in_r, in_w = IO.pipe
|
in_r, in_w = IO.pipe
|
||||||
opts[:in] = in_r
|
opts[:in] = in_r
|
||||||
in_w.sync = true
|
in_w.sync = true
|
||||||
@ -189,13 +177,7 @@ module Open3
|
|||||||
# }
|
# }
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
def popen2e(*cmd, &block)
|
def popen2e(*cmd, **opts, &block)
|
||||||
if Hash === cmd.last
|
|
||||||
opts = cmd.pop.dup
|
|
||||||
else
|
|
||||||
opts = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
in_r, in_w = IO.pipe
|
in_r, in_w = IO.pipe
|
||||||
opts[:in] = in_r
|
opts[:in] = in_r
|
||||||
in_w.sync = true
|
in_w.sync = true
|
||||||
@ -266,16 +248,7 @@ module Open3
|
|||||||
# STDOUT.binmode; print thumnail
|
# STDOUT.binmode; print thumnail
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
def capture3(*cmd)
|
def capture3(*cmd, stdin_data: '', binmode: false, **opts)
|
||||||
if Hash === cmd.last
|
|
||||||
opts = cmd.pop.dup
|
|
||||||
else
|
|
||||||
opts = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
stdin_data = opts.delete(:stdin_data) || ''
|
|
||||||
binmode = opts.delete(:binmode)
|
|
||||||
|
|
||||||
popen3(*cmd, opts) {|i, o, e, t|
|
popen3(*cmd, opts) {|i, o, e, t|
|
||||||
if binmode
|
if binmode
|
||||||
i.binmode
|
i.binmode
|
||||||
@ -320,16 +293,7 @@ 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)
|
def capture2(*cmd, stdin_data: '', binmode: false, **opts)
|
||||||
if Hash === cmd.last
|
|
||||||
opts = cmd.pop.dup
|
|
||||||
else
|
|
||||||
opts = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
stdin_data = opts.delete(:stdin_data) || ''
|
|
||||||
binmode = opts.delete(:binmode)
|
|
||||||
|
|
||||||
popen2(*cmd, opts) {|i, o, t|
|
popen2(*cmd, opts) {|i, o, t|
|
||||||
if binmode
|
if binmode
|
||||||
i.binmode
|
i.binmode
|
||||||
@ -359,16 +323,7 @@ module Open3
|
|||||||
# # capture make log
|
# # capture make log
|
||||||
# make_log, s = Open3.capture2e("make")
|
# make_log, s = Open3.capture2e("make")
|
||||||
#
|
#
|
||||||
def capture2e(*cmd)
|
def capture2e(*cmd, stdin_data: '', binmode: false, **opts)
|
||||||
if Hash === cmd.last
|
|
||||||
opts = cmd.pop.dup
|
|
||||||
else
|
|
||||||
opts = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
stdin_data = opts.delete(:stdin_data) || ''
|
|
||||||
binmode = opts.delete(:binmode)
|
|
||||||
|
|
||||||
popen2e(*cmd, opts) {|i, oe, t|
|
popen2e(*cmd, opts) {|i, oe, t|
|
||||||
if binmode
|
if binmode
|
||||||
i.binmode
|
i.binmode
|
||||||
@ -424,13 +379,7 @@ module Open3
|
|||||||
# stdin.close # send EOF to sort.
|
# stdin.close # send EOF to sort.
|
||||||
# p stdout.read #=> " 1\tbar\n 2\tbaz\n 3\tfoo\n"
|
# p stdout.read #=> " 1\tbar\n 2\tbaz\n 3\tfoo\n"
|
||||||
# }
|
# }
|
||||||
def pipeline_rw(*cmds, &block)
|
def pipeline_rw(*cmds, **opts, &block)
|
||||||
if Hash === cmds.last
|
|
||||||
opts = cmds.pop.dup
|
|
||||||
else
|
|
||||||
opts = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
in_r, in_w = IO.pipe
|
in_r, in_w = IO.pipe
|
||||||
opts[:in] = in_r
|
opts[:in] = in_r
|
||||||
in_w.sync = true
|
in_w.sync = true
|
||||||
@ -480,13 +429,7 @@ module Open3
|
|||||||
# p ts[1].value #=> #<Process::Status: pid 24913 exit 0>
|
# p ts[1].value #=> #<Process::Status: pid 24913 exit 0>
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
def pipeline_r(*cmds, &block)
|
def pipeline_r(*cmds, **opts, &block)
|
||||||
if Hash === cmds.last
|
|
||||||
opts = cmds.pop.dup
|
|
||||||
else
|
|
||||||
opts = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
out_r, out_w = IO.pipe
|
out_r, out_w = IO.pipe
|
||||||
opts[:out] = out_w
|
opts[:out] = out_w
|
||||||
|
|
||||||
@ -522,13 +465,7 @@ module Open3
|
|||||||
# i.puts "hello"
|
# i.puts "hello"
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
def pipeline_w(*cmds, &block)
|
def pipeline_w(*cmds, **opts, &block)
|
||||||
if Hash === cmds.last
|
|
||||||
opts = cmds.pop.dup
|
|
||||||
else
|
|
||||||
opts = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
in_r, in_w = IO.pipe
|
in_r, in_w = IO.pipe
|
||||||
opts[:in] = in_r
|
opts[:in] = in_r
|
||||||
in_w.sync = true
|
in_w.sync = true
|
||||||
@ -581,13 +518,7 @@ module Open3
|
|||||||
# p err_r.read # error messages of pdftops and lpr.
|
# p err_r.read # error messages of pdftops and lpr.
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
def pipeline_start(*cmds, &block)
|
def pipeline_start(*cmds, **opts, &block)
|
||||||
if Hash === cmds.last
|
|
||||||
opts = cmds.pop.dup
|
|
||||||
else
|
|
||||||
opts = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
if block
|
if block
|
||||||
pipeline_run(cmds, opts, [], [], &block)
|
pipeline_run(cmds, opts, [], [], &block)
|
||||||
else
|
else
|
||||||
@ -649,13 +580,7 @@ module Open3
|
|||||||
# # 106
|
# # 106
|
||||||
# # 202
|
# # 202
|
||||||
#
|
#
|
||||||
def pipeline(*cmds)
|
def pipeline(*cmds, **opts)
|
||||||
if Hash === cmds.last
|
|
||||||
opts = cmds.pop.dup
|
|
||||||
else
|
|
||||||
opts = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
pipeline_run(cmds, opts, [], []) {|ts|
|
pipeline_run(cmds, opts, [], []) {|ts|
|
||||||
ts.map {|t| t.value }
|
ts.map {|t| t.value }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user