# Quoting problem with %x

**URL:** <https://www.ruby-forum.com/t/quoting-problem-with-x/158415>\
**Category:** Ruby\
**Created:** [January 23, 2009, 2:01am UTC](https://www.ruby-forum.com/t/quoting-problem-with-x/158415 "2009-01-23T02:01:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![will\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a87d85/32.png) [@will\_p](https://www.ruby-forum.com/u/will_p)\
**Post date:** [January 23, 2009, 2:01am UTC](https://www.ruby-forum.com/t/quoting-problem-with-x/158415/1 "2009-01-23T02:01:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![will\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a87d85/32.png) [@will\_p](https://www.ruby-forum.com/u/will_p)\
**Post date:** [January 23, 2009, 5:18pm UTC](https://www.ruby-forum.com/t/quoting-problem-with-x/158415/2 "2009-01-23T17:18:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![will\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a87d85/32.png) [@will\_p](https://www.ruby-forum.com/u/will_p)\
**Post date:** [February 2, 2009, 7:35pm UTC](https://www.ruby-forum.com/t/quoting-problem-with-x/158415/3 "2009-02-02T19:35:50Z")

</div>

On Jan 22, 7:57 pm, Will P. [removed\_email\_address@domain.invalid](mailto: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
