5

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!

1
  • 4
    Your code uses single quotes in the exec string. In single quote strings Ruby does not provide interpolation (#{}). That could aslo be the error. Commented Nov 30, 2011 at 23:10

2 Answers 2

9

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I think your comment might be closer to the real problem, the # in 'sh #{_shellScript}' will be seen as a comment so it will be the same as saying exec 'sh' and there's command prompt.
You might be fixing the current bug (single instead of double quotes) and the next one (exec instead of system) at the same time :)
1

Just try the following line:

%x[#{_shellScript}]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.