77件ヒット
[1-77件を表示]
(0.053秒)
検索結果
先頭5件
-
IO
# reopen(path) -> self (32215.0) -
path で指定されたファイルにストリームを繋ぎ換えます。
...int("This is line three\n")
f2.readlines # => ["This is line one\n", "This is line two\n"]
f1.close
f2.reopen("testfile", "r") # => #<File:testfile>
f2.readlines # => ["This is line one\n", "This is line two\n", "This is line three\n"]
f2.close
//}
@see Kernel.#open... -
IO
# reopen(path , mode) -> self (32215.0) -
path で指定されたファイルにストリームを繋ぎ換えます。
...int("This is line three\n")
f2.readlines # => ["This is line one\n", "This is line two\n"]
f1.close
f2.reopen("testfile", "r") # => #<File:testfile>
f2.readlines # => ["This is line one\n", "This is line two\n", "This is line three\n"]
f2.close
//}
@see Kernel.#open... -
IO
# reopen(io) -> self (32205.0) -
自身を指定された io に繋ぎ換えます。
自身を指定された io に繋ぎ換えます。
クラスも io に等しくなることに注意してください。
IO#pos, IO#lineno などは指定された io と等しくなります。
@param io 自身を繋ぎ換えたい IO オブジェクトを指定します。
@raise IOError 指定された io が close されている場合に発生します。 -
Kernel
$ $ > -> object (8030.0) -
標準出力です。
...ut = File.open("/tmp/foo", "w")
puts "foo" # 出力する
$stdout = STDOUT # 元に戻す
//}
自プロセスだけでなく、子プロセスの標準出力もリダイレクトしたいときは
以下のように IO#reopen を使います。
//emlist[例][ruby]{
STDOUT.reopen("/tmp/fo......# 元の $stdout を保存する
$stdout.reopen("/tmp/foo") # $stdout を /tmp/foo にリダイレクトする
puts "foo" # /tmp/foo に出力
$stdout.flush # 念のためフラッシュする
$stdout.reopen stdout_old # 元に戻す
//}
$stdout... -
Kernel
$ $ stderr -> object (8030.0) -
標準エラー出力です。
...File.open("/tmp/foo", "w")
puts "foo" # 出力する
$stderr = STDERR # 元に戻す
//}
自プロセスだけでなく、子プロセスの標準エラー出力も
リダイレクトしたいときは以下のように IO#reopen を使います。
//emlist[例][ruby]{
$stderr.reopen("/t......# 元の $stderr を保存する
$stderr.reopen("/tmp/foo") # $stderr を /tmp/foo にリダイレクトする
puts "foo" # /tmp/foo に出力
$stderr.flush # 念のためフラッシュする
$stderr.reopen stderr_old # 元に戻す
//}
$stderr... -
Kernel
$ $ stdin -> object (8030.0) -
標準入力です。
...クトしたいときは
$stdin に代入すれば十分です。
//emlist[例][ruby]{
# 標準入力の入力元 /tmp/foo に変更
$stdin = File.open("/tmp/foo", "r")
gets # 入力する
$stdin = STDIN # 元に戻す
//}
ただし、Kernel.#gets など、特定の組み込み......IO#reopen を使います。
//emlist[例][ruby]{
$stdin.reopen("/tmp/foo")
//}
また、リダイレクトしたあと
出力先をまた元に戻したい場合は以下のようにします。
//emlist[例][ruby]{
stdin_old = $stdin.dup # 元の $stdin を保存する
$stdout.reopen("/t......mp/foo") # $stdin を /tmp/foo にリダイレクトする
gets # /tmp/foo から入力
$stdin.reopen stdin_old # 元に戻す
//}
$stdin はグローバルスコープです。... -
Kernel
$ $ stdout -> object (8030.0) -
標準出力です。
...ut = File.open("/tmp/foo", "w")
puts "foo" # 出力する
$stdout = STDOUT # 元に戻す
//}
自プロセスだけでなく、子プロセスの標準出力もリダイレクトしたいときは
以下のように IO#reopen を使います。
//emlist[例][ruby]{
STDOUT.reopen("/tmp/fo......# 元の $stdout を保存する
$stdout.reopen("/tmp/foo") # $stdout を /tmp/foo にリダイレクトする
puts "foo" # /tmp/foo に出力
$stdout.flush # 念のためフラッシュする
$stdout.reopen stdout_old # 元に戻す
//}
$stdout...