Popen needs escaped pathname?

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.

Matt N. wrote:

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

Joel VanderWerf [email protected] wrote:

Matt N. wrote:

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…

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs