问题
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