Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing shell script from ruby script

Tags:

shell

ruby

I have the following:

_shellScript = "../Dependency/test.sh"
exec 'sh #{_shellScript}'

But when I go to execute the ruby script it ends me up at a shell prompt instead of executing the script that is located within the variable _shellScript.

Any ideas would be appreciated!

like image 623
Danny Avatar asked Jan 19 '23 04:01

Danny


1 Answers

In Ruby, exec ends the Ruby process and passes the shell to the child specified. If you need to give all of test.sh's output to your console, you want system("sh #{_shellScript}"). If you need to give data and receive it through stdin and stdout, look at popen.

like image 169
Linuxios Avatar answered Jan 24 '23 23:01

Linuxios