popen needs escaped pathname?

M

Matt Neuburg

I am using popen to pipe some text through a Perl script and I've just
discovered (accidentally) that the pathname for this script has to be
explicitly escaped - it must not contain unescaped spaces. This
surprised me because elsewhere in Ruby this does not appear to be the
case (in "require", for example). What is the rule here? Thx - m.
 
J

Joel VanderWerf

Matt said:
I am using popen to pipe some text through a Perl script and I've just
discovered (accidentally) that the pathname for this script has to be
explicitly escaped - it must not contain unescaped spaces. This
surprised me because elsewhere in Ruby this does not appear to be the
case (in "require", for example). What is the rule here? Thx - m.

It's a shell thing...

pipe = IO.popen("ls *", "r")

doesn't look for a program named "ls *".

It's like the difference between

system("ls *")

and

system("ls", "*")

except that in the case of IO.popen there is no (AFAICT) way to do the
latter. On platforms with fork() you can emulate it:

IO.popen("-", "r") do |pipe|
if pipe
puts pipe.read
else
exec "ls", "*" # error if there is no file named "*"
end
end
 
M

Matt Neuburg

Joel VanderWerf said:
It's a shell thing...

Right, I see; I'm talking directly to the shell...

I think the docs should tell me this!

So the same syntax that works in backticks will work here.

Thx - m.
 

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

Forum statistics

Threads
474,170
Messages
2,570,925
Members
47,464
Latest member
Bobbylenly

Latest Threads

Top