开发者

How to log system command output in Rails under production mode?

开发者 https://www.devze.com 2023-01-24 11:25 出处:网络
I\'m calling a C executable in my Rails(-v 2.3.5) application using the system() call. makefile_path = File.expand_path(\'./c_executalbe\', Rails.root)

I'm calling a C executable in my Rails(-v 2.3.5) application using the system() call.

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

Everything works fine on my local machine but for some reason that system() call won't run on the server(dreamhost). And there is no error message in log/production.log. 开发者_StackOverflow中文版I would like to see the returned output of that system call in the log. How can I do that?

Thanks in advance!


See: http://ruby-doc.org/core/classes/Kernel.html#M005960

Usage:

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

You'll get the command output.

If command comes from a variable, as in your case, you can interpolate:

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

To log it into log/production.log:

logger.info output
# or
puts output
0

精彩评论

暂无评论...
验证码 换一张
取 消