本文簡要介紹ruby語言中 Open3.pipeline_rw
的用法。
用法
pipeline_rw(*cmds, &block)
Open3.pipeline_rw
將命令列表作為管道啟動,管道連接到第一個命令的標準輸入和最後一個命令的標準輸出。
Open3.pipeline_rw(cmd1, cmd2, ... [, opts]) {|first_stdin, last_stdout, wait_threads| ... } first_stdin, last_stdout, wait_threads = Open3.pipeline_rw(cmd1, cmd2, ... [, opts]) ... first_stdin.close last_stdout.close
每個 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.
傳遞給 Process.spawn
的選項是通過合並數組的最後一個哈希元素 opts
以及每個命令之間的管道規範來構造的。
例子:
Open3.pipeline_rw("tr -dc A-Za-z", "wc -c") {|i, o, ts|
i.puts "All persons more than a mile high to leave the court."
i.close
p o.gets #=> "42\n"
}
Open3.pipeline_rw("sort", "cat -n") {|stdin, stdout, wait_thrs|
stdin.puts "foo"
stdin.puts "bar"
stdin.puts "baz"
stdin.close # send EOF to sort.
p stdout.read #=> " 1\tbar\n 2\tbaz\n 3\tfoo\n"
}
相關用法
- Ruby Open3.pipeline_r用法及代碼示例
- Ruby Open3.pipeline_w用法及代碼示例
- Ruby Open3.pipeline_start用法及代碼示例
- 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_rw。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。