0

I know how to run a script from within Ruby. I usually use back ticks and they work fine. Recently we got request to feed one more argument to the script and problem happens here.

Originally, it looks like this: a global variable defined as:

SCRIPT = "/opt/customer/send_command.pl"

Then, we call

status =`"#{SCRIPT}" -c "ctl.pl qstatus"`
queue = `"#{SCRIPT}" -c "ctl.pl queue"`

Everything is fine. Now, there's one more parameter to feed in the script send_command.pl. So I changed global variable SCRIPT to:

SCRIPT = "/opt/customer/send_command.pl -p production"

And I use the same way to call that script:

status =`"#{SCRIPT}" -c "ctl.pl qstatus"`

But I got the error message:

sh: /opt/customer/send_command.pl -p production: not found

If I ditch SCRIPT variable, just call the script directly like:

status = `/opt/customer/send_command.pl -p production -c "ctl.pl qstatus"`

and it works as expected.

My question is why that happens and how to fix it? I guess I could just manually put -p production everywhere, but it's less ideal and very error prone.

2 Answers 2

6

It didn't work because you have extra double quotes. To fix it, remove them.

status =`#{SCRIPT} -c "ctl.pl qstatus"`
Sign up to request clarification or add additional context in comments.

2 Comments

Interestingly, running "ls", "pwd" (with the extra double quotes) in the shell all work just fine on OSX.
Yeyeye. I was just noticing the SCRIPT = "/opt/customer/send_command.pl -p production" part. That assuredly wouldn't work.
1

Either remove the double quotes:

from:

status =`"#{SCRIPT}" -c "ctl.pl qstatus"`

to

status =`#{SCRIPT} -c "ctl.pl qstatus"`

unless you want to try escaping them like:

status ="#{SCRIPT} -c \"ctl.pl qstatus\""

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.