如何在生产模式下记录Rails系统命令输出?

3

我正在使用system()调用在我的Rails(-v 2.3.5)应用程序中调用一个C可执行文件。

makefile_path = File.expand_path('./c_executalbe', Rails.root)
system(makefile_path)

我的本地机器上一切都正常,但在服务器(dreamhost)上那个system()调用却无法运行。而且在log/production.log中也没有错误信息。我想在日志中看到该系统调用的返回输出。我该怎么做呢?

提前感谢您的帮助!

1个回答

6

请参考:http://ruby-doc.org/core/classes/Kernel.html#M005960

用法:

output = %x(command)
output = `command`
output = Kernel.send(:`, "command")

您将获得命令输出。

如果command来自变量,就像您的情况一样,您可以进行插值:

output = %x(#{makefile_path})
output = `#{makefile_path}`
output = Kernel.send(:`, makefile_path)

将其记录到log/production.log中:

logger.info output
# or
puts output

我无法在使用thin服务器的生产环境中记录日志 Logger.info(cmd_output)。 - Omer Aslam

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接