Tag: iostream

将全局$ stdout重新分配给console – ruby

我试图设置$ stdout暂时写入文件然后回到文件。 test.rb : old_stdout = $stdout $stdout.reopen(“mytestfile.out”,’w+’) puts “this goes in mytestfile” $stdout= old_stdout puts “this should be on the console” $stdout.reopen(“mytestfile1.out”,’w+’) puts “this goes in mytestfile1:” $stdout = old_stdout puts “this should be back on the console” 这是输出。 ruby test.rb => no output on the console cat mytestfile.out this goes in mytestfile this […]