How to run a console command line through a Ruby on Rails web application and return results?

I have a web service that its taks should run a specific application, but the application does not have any threads but a console, so I need to find a way to redirect my requests to the console (STDOUT), and then get the results returned from the output.

but i don't know how to do this in ruby ​​on rails 1.9.

considers

+7
source share
2 answers

There are several ways to run a system command using ruby. You can refer to this article I write last time, if it helps

http://www.shanison.com/2010/09/01/ruby-capture-output-in-realtime/

+3
source

It's a little late, but I will leave it here for others looking for something like that.
In my opinion, the easiest way to execute a system command and get its results in Ruby is to encapsulate the system command, which will be executed in reverse ticks. For example,

result = 'ls -a' #This would run 'ls-a' and return its output, to our variable "result" 

This article describes other ways to run system commands using Ruby.

0
source

All Articles