将 Ruby 控制台输出写入文本文件 [英] Writing Ruby Console Output to Text File

查看:22
本文介绍了将 Ruby 控制台输出写入文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个 Ruby 应用程序,它将信息输出到控制台.我想让这个输出保存到文本/日志文件中.这甚至可能吗?ruby 必须有一个 flag 才能做到这一点?

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?

推荐答案

使用 shell 重定向:

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

另外,你也可以重定向 $stdout, $stderr:

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

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

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

这篇关于将 Ruby 控制台输出写入文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆