別のキーワード
種類
- モジュール関数 (85)
- インスタンスメソッド (24)
- 特異メソッド (11)
- 文書 (11)
ライブラリ
- ビルトイン (55)
- open3 (22)
-
shell
/ command-processor (24) - timeout (19)
クラス
検索結果
先頭5件
-
Shell
:: CommandProcessor # echo(*strings) -> Shell :: Filter (21113.0) -
実行すると, それらを内容とする Filter オブジェクトを返します.
...ings シェルコマンド echo に与える引数を文字列で指定します。
動作例
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!
cat(file).each { |l|
echo(l) | tee(file + ".tee")... -
Process
. exec(command , *args) -> () (21012.0) -
カレントプロセスを与えられた外部コマンドで置き換えます。
...からいくつかの環境を引き継ぎます。
@param command 実行する外部コマンド。
@param args command に渡す引数。
exec "echo *" # echoes list of files in current directory
# never get here
exec "echo", "*" # echoes an asterisk
# never get here... -
Shell
:: CommandProcessor # cat(*files) -> Shell :: Filter (3006.0) -
実行すると, それらを内容とする Filter オブジェクトを返します.
...ファイル名を文字列で指定します。
動作例
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!
cat(file).each { |l|
echo(l) | tee(file + ".tee") >> "all.tee"
}
}
}... -
Shell
:: CommandProcessor # glob(pattern) -> Shell :: Filter (3006.0) -
実行すると, それらを内容とする Filter オブジェクトを返します.
...Dir.[] を参照してください。
動作例
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!
cat(file).each { |l|
echo(l) | tee(file + ".tee") >> "all.tee"
}
}
}
@see Dir.[]... -
Shell
:: CommandProcessor # tee(file) -> Shell :: Filter (3006.0) -
実行すると, それらを内容とする Filter オブジェクトを返します.
...るファイル名を文字列で指定します。
動作例
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!
cat(file).each { |l|
echo(l) | tee(file + ".tee") >> "all.tee"
}
}
}... -
Open3
. # capture2e(*cmd) -> [String , Process :: Status] (113.0) -
cmdで指定されたコマンドを実行し、そのプロセスの標準出力と標準エラーを1 つの文字列にしたものとプロセスの終了ステータスを表すオブジェクトを返し ます。
...をバイナリモードに指定します。
例:
require "open3"
o, s = Open3.capture2e("echo a; sort >&2", :stdin_data=>"foo\nbar\nbaz\n")
p o #=> "a\nbar\nbaz\nfoo\n"
p s #=> #<Process::Status: pid 20574 exit 0>
Open3.#popen3と同様に引数に環境変数とオプションを指... -
Open3
. # capture3(*cmd) -> [String , String , Process :: Status] (113.0) -
cmdで指定されたコマンドを実行し、そのプロセスの標準出力と標準エラー、プ ロセスの終了ステータスを表すオブジェクトを返します。
...ナリモードに指定します。
例:
require "open3"
o, e, s = Open3.capture3("echo a; sort >&2", :stdin_data=>"foo\nbar\nbaz\n")
p o #=> "a\n"
p e #=> "bar\nbaz\nfoo\n"
p s #=> #<Process::Status: pid 32682 exit 0>
Open3.#popen3と同様に引数に環境変数とオプション... -
Kernel
. # spawn(env , program , *args , options={}) -> Integer (54.0) -
引数を外部コマンドとして実行しますが、生成した 子プロセスの終了を待ち合わせません。生成した子プロセスのプロセスIDを返します。
...AR にして BAZ を削除する
pid = spawn({"FOO"=>"BAR", "BAZ"=>nil}, command)
//}
親プロセスは Process.#waitpid で子プロセスの終了を待ち合わせるか
もしくは Process.#detach で子プロセスを切り離すかしてください。
そうでないとゾンビプロセ......プを変更しません。デフォルトは nil です。
: :rlimit_core, :rlimit_cpu, etc
resource limit を設定します。詳しくは Process.#setrlimit を見て
ください。引数には整数、もしくは整数2つの配列を渡します。
: :chdir
指定した文字列を......IO.popen で、子プロセスの
stderr と stdout を混ぜる例を以下に示します。
//emlist[][ruby]{
io = IO.popen(["sh", "-c", "echo out; echo err >&2", :err=>[:child, :out]])
p io.read #=> "out\nerr\n
//}
spawn と IO.popen では
デフォルトでは非標準的なファイルデス... -
Kernel
. # spawn(program , *args) -> Integer (54.0) -
引数を外部コマンドとして実行しますが、生成した 子プロセスの終了を待ち合わせません。生成した子プロセスのプロセスIDを返します。
...AR にして BAZ を削除する
pid = spawn({"FOO"=>"BAR", "BAZ"=>nil}, command)
//}
親プロセスは Process.#waitpid で子プロセスの終了を待ち合わせるか
もしくは Process.#detach で子プロセスを切り離すかしてください。
そうでないとゾンビプロセ......プを変更しません。デフォルトは nil です。
: :rlimit_core, :rlimit_cpu, etc
resource limit を設定します。詳しくは Process.#setrlimit を見て
ください。引数には整数、もしくは整数2つの配列を渡します。
: :chdir
指定した文字列を......IO.popen で、子プロセスの
stderr と stdout を混ぜる例を以下に示します。
//emlist[][ruby]{
io = IO.popen(["sh", "-c", "echo out; echo err >&2", :err=>[:child, :out]])
p io.read #=> "out\nerr\n
//}
spawn と IO.popen では
デフォルトでは非標準的なファイルデス... -
Timeout
. # timeout(sec , exception _ class = nil) {|i| . . . } -> object (30.0) -
ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 Timeout::Error が発生します。
...OT
#!/bin/bash
S="scale=10"
M=32767
trap 'echo "$S; $m1/($m1+$m2)*4" | bc ; echo "count = $((m1+m2))" ; exit 0' INT
m1=0
m2=0
while true
do
x="($RANDOM/$M)"
y="($RANDOM/$M)"
c=$(echo "$S;$x^2+$y^2 < 1.0" | bc)
echo $x $y $c
if [ $c -eq 1 ]
then
let m1......pid = com.pid
while line = com.gets
print line
end
}
rescue Timeout::Error => err
puts "timeout: shell execution."
Process.kill('SIGINT', pid)
printf "[result]\t%s", com.read
com.close unless com.nil?
end
#止まっているか確認する。
#system(... -
Timeout
. # timeout(sec , exception _ class , message) {|i| . . . } -> object (30.0) -
ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 Timeout::Error が発生します。
...OT
#!/bin/bash
S="scale=10"
M=32767
trap 'echo "$S; $m1/($m1+$m2)*4" | bc ; echo "count = $((m1+m2))" ; exit 0' INT
m1=0
m2=0
while true
do
x="($RANDOM/$M)"
y="($RANDOM/$M)"
c=$(echo "$S;$x^2+$y^2 < 1.0" | bc)
echo $x $y $c
if [ $c -eq 1 ]
then
let m1......pid = com.pid
while line = com.gets
print line
end
}
rescue Timeout::Error => err
puts "timeout: shell execution."
Process.kill('SIGINT', pid)
printf "[result]\t%s", com.read
com.close unless com.nil?
end
#止まっているか確認する。
#system(... -
ruby 1
. 6 feature (18.0) -
ruby 1.6 feature ruby version 1.6 は安定版です。この版での変更はバグ修正がメイン になります。
...なりました。((<ruby-bugs-ja:PR#205>))
* ((<Enumerable/each_with_index>)) が self を返すようになった(以前は nil)
* ((<Process/Process.setpgrp>)) が返す値が不定だった。
* ((<String/ljust>)), ((<String/rjust>)), ((<String/center>)) の結果に
変化がなく......るファイル名を指定したとき、拡張子がついてな
いとロードできなくなっていました。((<ruby-dev:13756>))
$ echo p __FILE__ > ~/a.rb
$ ruby17 -v -r~/a -e0
ruby 1.7.1 (2001-07-03) [i686-linux]
0: No such file to load -- ~/a (LoadError)
$ ruby16...