Forum: Ruby quoting problem with %x

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Will P. (Guest)
on 2009-01-23 03:01
(Received via mailing list)
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?
Sandor Szücs (Guest)
on 2009-01-23 18:18
(Received via mailing list)
On 23.01.2009, at 01:58, Will P. wrote:

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

 >> %x[echo \'bla\']
=> "bla\n"
 >> %x[echo \\'bla\\']
=> "'bla'\n"

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

Regards, Sandor
Szücs
t3ch.dude (Guest)
on 2009-02-02 20:35
(Received via mailing list)
On Jan 22, 7:57 pm, Will P. <removed_email_address@domain.invalid> wrote:
> 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
This topic is locked and can not be replied to.