本文简要介绍ruby语言中 Open3.pipeline_start
的用法。
用法
pipeline_start(*cmds, &block)
Open3.pipeline_start
将命令列表作为管道启动。没有为第一个命令的标准输入和最后一个命令的标准输出创建管道。
Open3.pipeline_start(cmd1, cmd2, ... [, opts]) {|wait_threads| ... } wait_threads = Open3.pipeline_start(cmd1, cmd2, ... [, opts]) ...
每个 cmd 都是一个字符串或一个数组。如果它是一个数组,则将元素传递给 Process.spawn
。
cmd: commandline command line string which is passed to a shell [env, commandline, opts] command line string which is passed to a shell [env, cmdname, arg1, ..., opts] command name and one or more arguments (no shell) [env, [cmdname, argv0], arg1, ..., opts] command name and arguments including argv[0] (no shell) Note that env and opts are optional, as for Process.spawn.
例子:
# Run xeyes in 10 seconds.
Open3.pipeline_start("xeyes") {|ts|
sleep 10
t = ts[0]
Process.kill("TERM", t.pid)
p t.value #=> #<Process::Status: pid 911 SIGTERM (signal 15)>
}
# Convert pdf to ps and send it to a printer.
# Collect error message of pdftops and lpr.
pdf_file = "paper.pdf"
printer = "printer-name"
err_r, err_w = IO.pipe
Open3.pipeline_start(["pdftops", pdf_file, "-"],
["lpr", "-P#{printer}"],
:err=>err_w) {|ts|
err_w.close
p err_r.read # error messages of pdftops and lpr.
}
相关用法
- Ruby Open3.pipeline_rw用法及代码示例
- Ruby Open3.pipeline_w用法及代码示例
- Ruby Open3.pipeline_r用法及代码示例
- Ruby Open3.pipeline用法及代码示例
- Ruby Open3.popen2e用法及代码示例
- Ruby Open3.popen3用法及代码示例
- Ruby Open3.popen2用法及代码示例
- Ruby Open3.capture3用法及代码示例
- Ruby Open3.capture2用法及代码示例
- Ruby Open3.capture2e用法及代码示例
- Ruby OpenStruct.ostruct[name] =用法及代码示例
- Ruby OpenSSL.fips_mode =用法及代码示例
- Ruby OpenSSL模块用法及代码示例
- Ruby OpenRead.open用法及代码示例
- Ruby OpenSSL.print_mem_leaks用法及代码示例
- Ruby OpenURI模块用法及代码示例
- Ruby OpenStruct类用法及代码示例
- Ruby OpenSSL.Digest用法及代码示例
- Ruby OpenStruct.==用法及代码示例
- Ruby OpenStruct.each_pair用法及代码示例
- Ruby OpenStruct.delete_field用法及代码示例
- Ruby OpenStruct.dig用法及代码示例
- Ruby OpenStruct.new用法及代码示例
- Ruby OpenStruct.ostruct[name]用法及代码示例
- Ruby Option.level用法及代码示例
注:本文由纯净天空筛选整理自ruby-lang.org大神的英文原创作品 Open3.pipeline_start。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。