【发布时间】:2015-04-08 20:32:53
【问题描述】:
由于某种原因,我无法在最后一行打印任何内容。
prev_std = STDOUT
$stdout = File.open(reportname, 'w')
# Several things happen to print to STDOUT here
$stdout = STDOUT
# Tell them that the report was written
puts "Report written to #{ reportname }"
# Slurp in the report ( FIXME )
reporttext = File.open(reportname, 'r') { |f| f.read }
# Print out the report after ( FIXME )
puts reporttext
我刚刚将报告写入文件,但不知何故我无法将其读回屏幕。在这两种情况下,我都在代码中使用完全相同的字符串来引用文件。在 shell 提示符处检查证明文件已正确写入,但我仍然无法将其打印到屏幕上。
我在这里做错了什么?
【问题讨论】: