quoting problem with %x

W

Will Parsons

I'm having a problem invoking external programs from ruby that are passed
arguments containing spaces. I have a program that I would invoke outside
of ruby like:

progname -o 'something with spaces'

How do I get the output from this within ruby? If I run:

%x[progname -o 'something with spaces']

the single quotes get lost and the result is as if
"progname -o something with spaces" had been invoked.

Attempting to escape the quotes like:

%x[progname -o \'something with spaces\']

doesn't help. Can someone enlighten me on how this can be done?
 
S

Sandor Szücs

How do I get the output from this within ruby? If I run:

%x[progname -o 'something with spaces']

the single quotes get lost and the result is as if
"progname -o something with spaces" had been invoked.

Attempting to escape the quotes like:

%x[progname -o \'something with spaces\']

doesn't help. Can someone enlighten me on how this can be done?
%x[echo \'bla\'] =3D> "bla\n"
%x[echo \\'bla\\']
=3D> "'bla'\n"

Try it in irb and you will see what you get.

Regards, Sandor Sz=FCcs
--
 
T

t3ch.dude

I'm having aprobleminvoking external programs from ruby that are passed
arguments containing spaces.  I have a program that I would invoke outside
of ruby like:

  progname -o 'something with spaces'

How do I get the output from this within ruby?  If I run:

Have you tried:

system("progname", "-o", "'something with spaces'")

or something similar?

-t3ch.dude
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,270
Latest member
TopCryptoTwitterChannels_

Latest Threads

Top