2010-11-12 59 views
1

我使用system()调用在我的Rails(-v 2.3.5)应用程序中调用C可执行文件。如何在生产模式下在Rails中记录系统命令输出?

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

一切正常,我的本地计算机上,但由于某种原因,system()调用不会在服务器(Dreamhost的)上运行。并且log/production.log中没有错误消息。我希望在日志中看到该系统调用的返回输出。我怎样才能做到这一点?

提前致谢!

回答

3

请参见: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 
+0

谢谢!这正是我所期待的。 – saurb 2010-11-14 06:37:53

+0

我无法使用Logger.info(cmd_output)将其记录在生产上。我正在使用瘦服务器。 – 2012-10-01 18:56:13