22件ヒット
[1-22件を表示]
(0.020秒)
別のキーワード
キーワード
-
$ DEFAULT _ INPUT (11) -
$ stdin (11)
検索結果
-
Kernel
$ $ DEFAULT _ INPUT -> IO (108.0) -
$< の別名
...$< の別名
require "English"
while line = $DEFAULT_INPUT.gets
p line
end
# end of sample.rb
ruby sample.rb < /etc/passwd
# => "hoge:x:500:501::/home/hoge:/bin/bash\n"
...... -
Kernel
$ $ stdin -> object (55.0) -
標準入力です。
...le.open("/tmp/foo", "r")
gets # 入力する
$stdin = STDIN # 元に戻す
//}
ただし、Kernel.#gets など、特定の組み込みメソッドは
$stdin オブジェクトにメソッドを転送して実装されています。
従って、Kernel.#gets などが正しく動......していなければいけません。
gets, readline, readlines, getc, readchar, tell, seek,
pos=, rewind, fileno, to_io, eof, each_line, each_byte,
binmode, closed?
//emlist[例][ruby]{
$stdin = Object.new
def $stdin.gets
"foo"
end
p gets() # => "foo"
//}
自プロセスだけ......でなく、子プロセスの標準入力もリダイレクトしたいときは
以下のように IO#reopen を使います。
//emlist[例][ruby]{
$stdin.reopen("/tmp/foo")
//}
また、リダイレクトしたあと
出力先をまた元に戻したい場合は以下のようにします。...