我正在使用 system() 调用在我的 Rails(-v 2.3.5) 应用程序中调用 C 可执行文件。
makefile_path = File.expand_path('./c_executalbe', Rails.root)
system(makefile_path)
在我的本地机器上一切正常,但由于某些原因,system() 调用无法在服务器 (dreamhost) 上运行。并且在log/production.log 中没有错误信息。我想在日志中看到该系统调用的返回输出。我该怎么做?
提前致谢!
最佳答案
参见: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
关于ruby-on-rails - 如何在生产模式下在 Rails 中记录系统命令输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4160537/