[英]How to execute a console command line through Ruby on Rails web application and get the results back?
I have a webservice which its taks is to execute a particualr application but the application doesn't have any sort of streaming but console , so I have to find a way to redirect my requests to the console(STDOUT) and then get the results back from the output.我有一个网络服务,它的任务是执行一个特定的应用程序,但该应用程序没有任何类型的流,但控制台,所以我必须找到一种方法将我的请求重定向到控制台(STDOUT),然后得到结果回来从输出。
but I don't have any idea how can I do this in ruby on rails 1.9.但我不知道如何在 ruby on rails 1.9 中做到这一点。
regards问候
This is a bit late, but I'll leave this here for others looking for something similar.这有点晚了,但我会把它留在这里,让其他人寻找类似的东西。
The simplest way, in my opinion, to execute a system command and grab its results in Ruby, is to encapsulate the system command to be executed in backticks.在我看来,在 Ruby 中执行系统命令并获取其结果的最简单方法是将要执行的系统命令封装在反引号中。 For example,
例如,
result = `ls -a` #This would run `ls-a` and return its output, to our variable "result"
This article describes other ways in which we could run system commands using Ruby. 本文描述了我们可以使用 Ruby 运行系统命令的其他方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.