更新时间:2023-12-05 13:03:40
覆盖 $ stdout
以重定向控制台输出:
You can use override $stdout
to redirect the console output:
$stdout = File.new('console.out', 'w')
您可能还需要调用一次:
You may also need to call this once:
$stdout.sync = true
这将把所有输出重定向到文件。如果您要临时重定向输出,请确保您存储 $ stdout
的原始值,以便可以将其更改。
This will redirect all output to the file. If you want to temporarily redirect the output make sure that you store the original value of $stdout
so you can change it back.