Writing Ruby Console Output to Text File

本小妞迷上赌 提交于 2020-01-11 04:01:06

问题


I'm trying to run a Ruby application, which outputs information to the console. I'd like to make this output get saved to a text/log file. Is this even possible? There must be a flag for ruby to do this right?


回答1:


Use shell redirections:

ruby script.rb > out.txt
rails server > out.txt

On another note, you may also redirect $stdout, $stderr:

$stdout = File.new('/path/to/out.txt', 'w')

http://eddymulyono.livejournal.com/65791.html



来源:https://stackoverflow.com/questions/8720150/writing-ruby-console-output-to-text-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!