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

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

问题描述

我试图运行一个Ruby应用程序,它将信息输出到控制台。我想让这个输出保存到文本/日志文件中。
这甚至可能吗?

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 redirections

Use shell redirections:

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天全站免登陆