I want to execute an .exe file and get its result as a string to display in my application. How can I do this in ruby?
Asked
Active
Viewed 101 times
0
-
1You might want to take a look at [Running a command from Ruby displaying and capturing the output](http://stackoverflow.com/questions/10224481/running-a-command-from-ruby-displaying-and-capturing-the-output) – Alistair A. Israel Mar 06 '13 at 05:37
-
What is that exe file supposed to do? – tamizhgeek Mar 06 '13 at 05:38
1 Answers
2
Ruby has several ways of executing other apps in a sub-shell. The easiest is to use back-ticks to wrap the command:
`dir`
will create a sub-shell and execute the dir
command in it, then return the STDOUT output to Ruby. You can capture the output by assigning it to a variable:
output = `dir`

the Tin Man
- 158,662
- 42
- 215
- 303