モジュール
- Open3 (198)
キーワード
- capture2 (11)
- capture2e (11)
- capture3 (11)
- pipeline (11)
-
pipeline
_ r (22) -
pipeline
_ rw (22) -
pipeline
_ start (22) -
pipeline
_ w (22) - popen2 (22)
- popen2e (22)
- popen3 (22)
検索結果
先頭5件
-
Open3
. # pipeline(*cmds) -> [Process :: Status] (6214.0) -
指定したコマンドのリストをパイプで繋いで順番に実行します。
...それぞれのコマンドは
以下のように String か Array で指定します。
commandline にはコマンド全体(例. "nroff -man")を表す
String を指定します。
options には Hash で指定します。
env には環......ド名を表す String を指定します。
1、2、3 は shell 経由で実行されます。
(1) commandline
(2) [commandline, options]
(3) [env, commandline, options]
(4) [env, cmdname, arg1, arg2, ..., options]
(5) [env, [cmdname, argv0], arg1, ..., options]
@return 実行し......require "open3"
fname = "/usr/share/man/man1/ruby.1.gz"
p Open3.pipeline(["zcat", fname], "nroff -man", "less")
#=> [#<Process::Status: pid 11817 exit 0>,
# #<Process::Status: pid 11820 exit 0>,
# #<Process::Status: pid 11828 exit 0>]
例2:
require "open3"
Open3.pipeline([... -
Open3
. # pipeline _ r(*cmds) -> [IO , [Thread]] (6214.0) -
指定したコマンドのリストをパイプで繋いで順番に実行します。最後の コマンドの標準出力を受けとる事ができます。
...それぞれのコマンドは
以下のように String か Array で指定します。
commandline にはコマンド全体(例. "nroff -man")を表す
String を指定します。
options には Hash で指定します。
env には環......ド名を表す String を指定します。
1、2、3 は shell 経由で実行されます。
(1) commandline
(2) [commandline, options]
(3) [env, commandline, options]
(4) [env, cmdname, arg1, arg2, ..., options]
(5) [env, [cmdname, argv0], arg1, ..., options]
@return ブロッ......します。
例:
require "open3"
Open3.pipeline_r("yes", "head -10") {|r, ts|
p r.read #=> "y\ny\ny\ny\ny\ny\ny\ny\ny\ny\n"
p ts[0].value #=> #<Process::Status: pid 24910 SIGPIPE (signal 13)>
p ts[1].value #=> #<Process::Status: pid 24913 exit 0>
}
@see Open3.#popen3... -
Open3
. # pipeline _ r(*cmds) {|last _ stdout , wait _ thrs| . . . } -> () (6214.0) -
指定したコマンドのリストをパイプで繋いで順番に実行します。最後の コマンドの標準出力を受けとる事ができます。
...それぞれのコマンドは
以下のように String か Array で指定します。
commandline にはコマンド全体(例. "nroff -man")を表す
String を指定します。
options には Hash で指定します。
env には環......ド名を表す String を指定します。
1、2、3 は shell 経由で実行されます。
(1) commandline
(2) [commandline, options]
(3) [env, commandline, options]
(4) [env, cmdname, arg1, arg2, ..., options]
(5) [env, [cmdname, argv0], arg1, ..., options]
@return ブロッ......します。
例:
require "open3"
Open3.pipeline_r("yes", "head -10") {|r, ts|
p r.read #=> "y\ny\ny\ny\ny\ny\ny\ny\ny\ny\n"
p ts[0].value #=> #<Process::Status: pid 24910 SIGPIPE (signal 13)>
p ts[1].value #=> #<Process::Status: pid 24913 exit 0>
}
@see Open3.#popen3... -
Open3
. # pipeline _ rw(*cmds) -> [IO , IO , [Thread]] (6214.0) -
指定したコマンドのリストをパイプで繋いで順番に実行します。最初の コマンドの標準入力に書き込む事も最後のコマンドの標準出力を受けとる事も できます。
...それぞれのコマンドは
以下のように String か Array で指定します。
commandline にはコマンド全体(例. "nroff -man")を表す
String を指定します。
options には Hash で指定します。
env には環......ド名を表す String を指定します。
1、2、3 は shell 経由で実行されます。
(1) commandline
(2) [commandline, options]
(3) [env, commandline, options]
(4) [env, cmdname, arg1, arg2, ..., options]
(5) [env, [cmdname, argv0], arg1, ..., options]
@return ブロッ......配列で返します。
例:
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コマンド... -
Open3
. # pipeline _ rw(*cmds) {|first _ stdin , last _ stdout , wait _ thrs| . . . } -> () (6214.0) -
指定したコマンドのリストをパイプで繋いで順番に実行します。最初の コマンドの標準入力に書き込む事も最後のコマンドの標準出力を受けとる事も できます。
...それぞれのコマンドは
以下のように String か Array で指定します。
commandline にはコマンド全体(例. "nroff -man")を表す
String を指定します。
options には Hash で指定します。
env には環......ド名を表す String を指定します。
1、2、3 は shell 経由で実行されます。
(1) commandline
(2) [commandline, options]
(3) [env, commandline, options]
(4) [env, cmdname, arg1, arg2, ..., options]
(5) [env, [cmdname, argv0], arg1, ..., options]
@return ブロッ......配列で返します。
例:
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コマンド... -
Open3
. # pipeline _ w(*cmds) -> [IO , [Thread]] (6214.0) -
指定したコマンドのリストをパイプで繋いで順番に実行します。最初の コマンドの標準入力に書き込む事ができます。
...それぞれのコマンドは
以下のように String か Array で指定します。
commandline にはコマンド全体(例. "nroff -man")を表す
String を指定します。
options には Hash で指定します。
env には環......ド名を表す String を指定します。
1、2、3 は shell 経由で実行されます。
(1) commandline
(2) [commandline, options]
(3) [env, commandline, options]
(4) [env, cmdname, arg1, arg2, ..., options]
(5) [env, [cmdname, argv0], arg1, ..., options]
@return ブロッ......た場合は最初に実行するコマンドの標準入力、
実行したプロセスを待つためのスレッドの配列を配列で返します。
例:
require "open3"
Open3.pipeline_w("bzip2 -c", :out=>"/tmp/hello.bz2") {|w, ts|
w.puts "hello"
}
@see Open3.#popen3... -
Open3
. # pipeline _ w(*cmds) {|first _ stdin , wait _ thrs| . . . } -> () (6214.0) -
指定したコマンドのリストをパイプで繋いで順番に実行します。最初の コマンドの標準入力に書き込む事ができます。
...それぞれのコマンドは
以下のように String か Array で指定します。
commandline にはコマンド全体(例. "nroff -man")を表す
String を指定します。
options には Hash で指定します。
env には環......ド名を表す String を指定します。
1、2、3 は shell 経由で実行されます。
(1) commandline
(2) [commandline, options]
(3) [env, commandline, options]
(4) [env, cmdname, arg1, arg2, ..., options]
(5) [env, [cmdname, argv0], arg1, ..., options]
@return ブロッ......た場合は最初に実行するコマンドの標準入力、
実行したプロセスを待つためのスレッドの配列を配列で返します。
例:
require "open3"
Open3.pipeline_w("bzip2 -c", :out=>"/tmp/hello.bz2") {|w, ts|
w.puts "hello"
}
@see Open3.#popen3... -
Open3
. # pipeline _ start(*cmds) -> [Thread] (6208.0) -
指定したコマンドのリストをパイプで繋いで順番に実行します。
...それぞれのコマンドは
以下のように String か Array で指定します。
commandline にはコマンド全体(例. "nroff -man")を表す
String を指定します。
options には Hash で指定します。
env には環......ド名を表す String を指定します。
1、2、3 は shell 経由で実行されます。
(1) commandline
(2) [commandline, options]
(3) [env, commandline, options]
(4) [env, cmdname, arg1, arg2, ..., options]
(5) [env, [cmdname, argv0], arg1, ..., options]
@return ブロッ......ッ
ドの配列を返します。
例:
require "open3"
# xeyesを10秒だけ実行する。
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)>
}
@see Open3.#popen3... -
Open3
. # pipeline _ start(*cmds) {|wait _ thrs| . . . } -> () (6208.0) -
指定したコマンドのリストをパイプで繋いで順番に実行します。
...それぞれのコマンドは
以下のように String か Array で指定します。
commandline にはコマンド全体(例. "nroff -man")を表す
String を指定します。
options には Hash で指定します。
env には環......ド名を表す String を指定します。
1、2、3 は shell 経由で実行されます。
(1) commandline
(2) [commandline, options]
(3) [env, commandline, options]
(4) [env, cmdname, arg1, arg2, ..., options]
(5) [env, [cmdname, argv0], arg1, ..., options]
@return ブロッ......ッ
ドの配列を返します。
例:
require "open3"
# xeyesを10秒だけ実行する。
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)>
}
@see Open3.#popen3... -
Open3
. # popen3(*cmd) -> [IO , IO , IO , Thread] (432.0) -
外部プログラム cmd を実行し、そのプロセスの標準入力、標準出力、標準エラー 出力に接続されたパイプと実行したプロセスを待つためのスレッドを 4 要素の 配列で返します。
...イプと実行したプロセスを待つためのスレッドを 4 要素の
配列で返します。
require 'open3'
stdin, stdout, stderr, wait_thr = *Open3.popen3("/usr/bin/nroff -man")
@param cmd 実行するコマンドを指定します。
@return ブロックを指定した場合は......返します。
require 'open3'
Open3.popen3("read stdin; echo stdout; echo stderr >&2") {|stdin, stdout, stderr, wait_thr|
stdin.puts "stdin"
stdin.close # または close_write
p stdout.read
p stderr.read
}
#=> "stdout\n"
"stderr\n"
stdin への入力が終わ......ったらできる限り早く close か close_write
で閉じるべきです。
[UNIX系OS固有の注意] Open3 で作成した子プロセスは
wait(2) しなくてもゾンビになりません。
引数 cmd はそのまま Kernel.#spawn に渡されます。
Kernel.#spawnと同様に、引...