Using '&' as part of the command passed to IO.popen

Hey folks,

I’m having a problem calling a system command where
one of the parameters happens to contain an ampersand
(&). Popen apparently sees this as a command
separator, right? I’ve tried replacing it with \046,
but it gets processed before being passed to popen.
Anyone have any ideas?

Ruby 1.7.3 on Win2K

Jason

Hi,

···

----- Original Message -----
From: “Jason Persampieri” jason@persampieri.net
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Saturday, January 04, 2003 10:05 AM
Subject: using ‘&’ as part of the command passed to IO.popen

Hey folks,

I’m having a problem calling a system command where
one of the parameters happens to contain an ampersand
(&). Popen apparently sees this as a command
separator, right? I’ve tried replacing it with \046,
but it gets processed before being passed to popen.
Anyone have any ideas?

Ruby 1.7.3 on Win2K

According to microsoft document:

You can use multiple commands separated by the command separator && for
string, but you must enclose them in quotation marks
(for example, “command&&command&&command”).

The following special characters require quotation marks: & < > [ ] { } ^ =
; ! ’ + , ` ~ [white space]

Refer to http://www.microsoft.com/windowsxp/home/using/productdoc/en/Cmd.asp

You must quote like this:
popen("ruby -e ‘p ARGV’ “abc&def” ",“r”)

Park Heesob