Don't use system
, it does not capture STDOUT. Use backticks (or %x()
):
output = %x( #{my_script} )
Pergunta
I would like to run a shell script from my ruby file. Then capture its output and analyze it.
This is the scenario: - Within my ruby script I need to execute the my_script.sh - The shell script produce the followinf output in the terminal
> my_script.sh
xxxxx 1111
yyyyy 2222
zzzzz 3333
I'm using the following comand:
my_script = "/home/script.sh"
system("sh #{my_script}")
I'm not able to capture the output produced in the terminal for parsing
Solução
Don't use system
, it does not capture STDOUT. Use backticks (or %x()
):
output = %x( #{my_script} )