種類
- 特異メソッド (154)
- モジュール関数 (132)
- インスタンスメソッド (77)
クラス
- IO (198)
モジュール
- Enumerable (33)
- Kernel (132)
キーワード
- chunk (11)
-
close
_ read (11) -
close
_ write (11) - closed? (11)
- exec (44)
- fork (22)
- open (22)
- pid (11)
-
slice
_ before (22) - spawn (44)
検索結果
先頭5件
-
Kernel
. # open(file , mode _ enc = "r" , perm = 0666) {|io| . . . } -> object (14.0) -
file をオープンして、IO(Fileを含む)クラスのインスタンスを返します。
...の子プロセス
を生成し、その子プロセスとの間のパイプ(IOオブジェクト)を返し
ます。(このときの動作は、IO.popen と同じです。
File.open にはパイプラインを生成する機能はありません)。
Perlと異なりコマンドは常に `|' で始......ョンを整数で指定します。
@raise Errno::EXXX ファイルのオープンに失敗した場合に発生します。
@see File.open,IO.popen,IO.open
=== 第二引数のオープンモード・エンコーディング
文字列("mode" か "mode:ext_enc" か "mode:ext_enc:int_enc" とい... -
Enumerable
# chunk {|elt| . . . } -> Enumerator (8.0) -
要素を前から順にブロックで評価し、その結果によって 要素をチャンクに分けた(グループ化した)要素を持つ Enumerator を返します。
...の出力のハイフンの所で区切りたい場合を考えます。
//emlist[例][ruby]{
sep = "-"*72 + "\n" # ハイフンが72個の行
IO.popen("svn log README") {|f|
f.chunk {|line|
line != sep || nil
}.each {|_, lines|
pp lines
}
}
#=> ["r20018 | knu | 2008-10-29 13:20:42 +... -
Enumerable
# slice _ before {|elt| bool } -> Enumerator (8.0) -
パターンがマッチした要素、もしくはブロックが真を返した要素から 次にマッチする手前までを チャンク化(グループ化)したものを繰り返す Enumerator を 返します。
...ine| /\A\S/ === line }.each {|e| pp e}
}
# "svn proplist -R" の結果を分割する
# これは一要素が複数行にまたがっている
IO.popen([{"LC_ALL"=>"C"}, "svn", "proplist", "-R"]) {|f|
f.lines.slice_before(/\AProp/).each {|lines| p lines }
}
#=> ["Properties on '.':\n", " svn:ig... -
Enumerable
# slice _ before(pattern) -> Enumerator (8.0) -
パターンがマッチした要素、もしくはブロックが真を返した要素から 次にマッチする手前までを チャンク化(グループ化)したものを繰り返す Enumerator を 返します。
...ine| /\A\S/ === line }.each {|e| pp e}
}
# "svn proplist -R" の結果を分割する
# これは一要素が複数行にまたがっている
IO.popen([{"LC_ALL"=>"C"}, "svn", "proplist", "-R"]) {|f|
f.lines.slice_before(/\AProp/).each {|lines| p lines }
}
#=> ["Properties on '.':\n", " svn:ig... -
IO
# close _ read -> nil (8.0) -
読み込み用の IO を close します。主にパイプや読み書き両用に作成し た IO オブジェクトで使用します。
...オープンされていなければ発生します。
@raise Errno::EXXX close に失敗した場合に発生します。
//emlist[例][ruby]{
IO.popen("/bin/sh","r+") do |f|
f.close_read
# f.readlines # => IOError: not opened for reading
end
//}
@see IO#close, IO#closed?, IO#close_write... -
IO
# close _ write -> nil (8.0) -
書き込み用の IO を close します。
...プンされていなければ発生します。
@raise Errno::EXXX close に失敗した場合に発生します。
//emlist[例][ruby]{
f = IO.popen("/bin/sh","r+") do |f|
f.close_write
# f.print "nowhere" # => IOError: not opened for writing
end
//}
@see IO#close, IO#closed?, IO#close_read... -
IO
# closed? -> bool (8.0) -
self が完全に(読み込み用と書き込み用の両方が)クローズされている場合に true を返します。 そうでない場合は false を返します。
...します。
//emlist[例][ruby]{
IO.write("testfile", "test")
f = File.new("testfile")
f.close # => nil
f.closed? # => true
f = IO.popen("/bin/sh","r+")
f.close_write # => nil
f.closed? # => false
f.close_read # => nil
f.closed? # => true
//}
@see IO#close, IO#close... -
Kernel
. # exec(env , program , *args , options={}) -> () (8.0) -
引数で指定されたコマンドを実行します。
...替えて以下を実行
$ ps aux|grep sleep
xxxx 32754 0.0 0.0 2580 468 pts/3 S+ 22:01 0:00 mysleep 600
xxxx 32761 0.0 0.0 2824 792 pts/6 S+ 22:01 0:00 grep sleep
@see Kernel.#system,Kernel.#`,Kernel.#spawn,Kernel.#fork,IO.popen,IO.pipe,Kernel.#open,exec(3)... -
Kernel
. # exec(program , *args , options={}) -> () (8.0) -
引数で指定されたコマンドを実行します。
...替えて以下を実行
$ ps aux|grep sleep
xxxx 32754 0.0 0.0 2580 468 pts/3 S+ 22:01 0:00 mysleep 600
xxxx 32761 0.0 0.0 2824 792 pts/6 S+ 22:01 0:00 grep sleep
@see Kernel.#system,Kernel.#`,Kernel.#spawn,Kernel.#fork,IO.popen,IO.pipe,Kernel.#open,exec(3)... -
Kernel
. # fork -> Integer | nil (8.0) -
fork(2) システムコールを使ってプロセスの複製を作 ります。親プロセスでは子プロセスのプロセスIDを、子プロセスでは nil を返します。ブロックを指定して呼び出した場合には、生成し た子プロセスでブロックを評価します。
...puts "parent process. pid: #{Process.pid}, child pid: #{child_pid}"
# => parent process. pid: 79055, child pid: 79602
# 親プロセスでの処理
# ...
# 子プロセスの終了を待って終了。
Process.waitpid(child_pid)
//}
@see IO.popen,IO.pipe,Kernel.#at_exit,Kernel.#exit!, fork(2)...