Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm useing readpipe() to execute a cmd for me that I need info back from. It works, but only kind of.... here's what's happening.

@info = readpipe("ls (somefile without spaces in filename)");
The above works well. I like it. However...
@info = readpipe("ls (some file with spaces in filename)");
Gives me errors stating that the Shell doesn't know what to do with the command. Eg
root@bard:/usr/local/apache/cgi-bin# perl test.pl
ls: /mnt/mp3/misc/Toto: No such file or directory
ls: -: No such file or directory
ls: Africa.ogg: No such file or directory

Suggesstions? I have tried escaping the spaces, and that doesn't work either.

Replies are listed 'Best First'.
Re: readpipe problems.
by japhy (Canon) on Jun 21, 2001 at 03:04 UTC
    Try quoting the filename in the argument. And who uses readpipe() nowadays?!
    @res = `ls '$filename'`; # or @res = `ls \Q$filename\E`;


    japhy -- Perl and Regex Hacker
      And who uses readpipe() nowadays?!
      erm... the only desktop reference that I have currently is Perl in a Nutshell, which doesn't reference backticks. :)
      Thanks for the advice!

      E-
        It does, check page 45 :)
        Don't tell me you don't have the PODs... perlop is probably what you want too

        Greetz
        Beatnik
        ... Quidquid perl dictum sit, altum viditur.
Re: readpipe problems.
by Abigail (Deacon) on Jun 21, 2001 at 03:17 UTC
    Your quoting doesn't work because you aren't quoting at the right level. You need to quote the spaces from the shell, not Perl. You are using double quotes, so any backslashes are seen and interpreted by Perl, not the shell. Use double backslashes, single quotes or quotes around the file name.

    But why are you using readpipe? Why not just backticks?

    -- Abigail