キーワード
- kconv (12)
-
pipeline
_ r (12) -
pipeline
_ rw (12) -
pipeline
_ w (24) - popen2 (12)
- popen2e (12)
- popen3 (12)
- select (12)
- spawn (48)
- timeout (21)
- toutf16 (12)
- toutf32 (12)
- toutf8 (12)
検索結果
先頭5件
-
Timeout
. # timeout(sec , exception _ class = nil) {|i| . . . } -> object (9101.0) -
ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 Timeout::Error が発生します。
...秒の期限付きで実行します。
ブロックの実行時間が制限を過ぎたときは例外
Timeout::Error が発生します。
exception_class を指定した場合には Timeout::Error の代わりに
その例外が発生します。
ブロックパラメータ i は sec がはい......ト
require 'timeout'
def calc_pi(min)
loop do
x = rand
y = rand
x**2 + y**2 < 1.0 ? min[0] += 1 : min[1] += 1
end
end
t = 5
min = [ 0, 0]
begin
Timeout.timeout(t){
calc_pi(min)
}
rescue Timeout::Error
puts "timeout"
end
printf "%d:......タイムアウト
#!/usr/bin/env ruby
require 'timeout'
class MYError < Exception;end
begin
Timeout.timeout(5, MYError) {
sleep(30)
}
rescue MYError => err
puts "MYError"
puts err
end
=== 注意
timeout による割り込みは Thread によって実現され... -
Timeout
. # timeout(sec , exception _ class , message) {|i| . . . } -> object (9101.0) -
ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 Timeout::Error が発生します。
...秒の期限付きで実行します。
ブロックの実行時間が制限を過ぎたときは例外
Timeout::Error が発生します。
exception_class を指定した場合には Timeout::Error の代わりに
その例外が発生します。
ブロックパラメータ i は sec がはい......ト
require 'timeout'
def calc_pi(min)
loop do
x = rand
y = rand
x**2 + y**2 < 1.0 ? min[0] += 1 : min[1] += 1
end
end
t = 5
min = [ 0, 0]
begin
Timeout.timeout(t){
calc_pi(min)
}
rescue Timeout::Error
puts "timeout"
end
printf "%d:......タイムアウト
#!/usr/bin/env ruby
require 'timeout'
class MYError < Exception;end
begin
Timeout.timeout(5, MYError) {
sleep(30)
}
rescue MYError => err
puts "MYError"
puts err
end
=== 注意
timeout による割り込みは Thread によって実現され... -
Kconv
. # toutf16(str) -> String (6101.0) -
文字列 str のエンコーディングを UTF-16BE に変換して返します。
...ードされた文字列を展開し、
いわゆる半角カナを全角に変換します。
これらを変換したくない場合は、 NKF.#nkf('-w16xm0', str)
を使ってください。
Kconv.kconv(str, Kconv::UTF16)と同じです。
@param str 変換元の文字列
@see String#toutf16... -
Kconv
. # toutf32(str) -> String (6101.0) -
文字列 str のエンコーディングを UTF-32 に変換して返します。
...ードされた文字列を展開し、
いわゆる半角カナを全角に変換します。
これらを変換したくない場合は、 NKF.#nkf('-w32xm0', str)
を使ってください。
Kconv.kconv(str, Kconv::UTF32)と同じです。
@param str 変換元の文字列
@see String#toutf32... -
Kconv
. # toutf8(str) -> String (6101.0) -
文字列 str のエンコーディングを UTF-8 に変換して返します。
...コードされた文字列を展開し、
いわゆる半角カナを全角に変換します。
これらを変換したくない場合は、 NKF.#nkf('-wxm0', str)
を使ってください。
Kconv.kconv(str, Kconv::UTF8)と同じです。
@param str 変換元の文字列
@see String#toutf8... -
Kconv
. # kconv(str , out _ code , in _ code = Kconv :: AUTO) -> String (124.0) -
文字列 str のエンコーディングを out_code に変換したものを 返します。in_code も指定されていたら str のエンコーディングが in_code だとして動作します。
...文字列 str のエンコーディングを out_code に変換したものを
返します。in_code も指定されていたら str のエンコーディングが
in_code だとして動作します。
このメソッドはMIME エンコードされた文字列を展開し、
いわゆる半角......カナを全角に変換します。
これらを変換したくない場合は、 NKF.#nkf を使ってください。
@param str 変換元の文字列
@param out_code 変換後のエンコーディング
@param in_code strのエンコーディング
@see String#kconv... -
Kernel
. # select(reads , writes = [] , excepts = [] , timeout = nil) -> [[IO]] | nil (101.0) -
IO.select と同じです。
...IO.select と同じです。
@param reads IO.select 参照
@param writes IO.select 参照
@param excepts IO.select 参照
@param timeout IO.select 参照
@see IO.select... -
Open3
. # pipeline _ r(*cmds) {|last _ stdout , wait _ thrs| . . . } -> () (101.0) -
指定したコマンドのリストをパイプで繋いで順番に実行します。最後の コマンドの標準出力を受けとる事ができます。
指定したコマンドのリストをパイプで繋いで順番に実行します。最後の
コマンドの標準出力を受けとる事ができます。
@param cmds 実行するコマンドのリストを指定します。それぞれのコマンドは
以下のように String か Array で指定します。
commandline にはコマンド全体(例. "nroff -man")を表す
String を指定します。
options には Hash で指定します。
env には環境変数を Hash で指定します。
... -
Open3
. # pipeline _ rw(*cmds) {|first _ stdin , last _ stdout , wait _ thrs| . . . } -> () (101.0) -
指定したコマンドのリストをパイプで繋いで順番に実行します。最初の コマンドの標準入力に書き込む事も最後のコマンドの標準出力を受けとる事も できます。
...つため
のスレッドの配列を配列で返します。
例:
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 Open3.#popen3...