pipeline_rw(*cmds) -> [IO, IO, [Thread]][permalink][rdoc]pipeline_rw(*cmds) {|first_stdin, last_stdout, wait_thrs| ... } -> ()指定したコマンドのリストをパイプで繋いで順番に実行します。最初のコマンドの標準入力に書き込む事も最後のコマンドの標準出力を受けとる事もできます。
例:
require "open3"
Open3.pipeline_rw("sort", "cat -n") {|stdin, stdout, wait_thrs|
stdin.puts "foo"
stdin.puts "bar"
stdin.puts "baz"
# sortコマンドにEOFを送る。
stdin.close
# stdinに渡した文字列をsortコマンドが並べ替えたものに、catコマンド
# が行番号を付けた文字列が表示される。
p stdout.read #=> " 1\tbar\n 2\tbaz\n 3\tfoo\n"
}
[SEE_ALSO] Open3.#popen3