Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Shell.pm mangling arguments with embedded whitespace?

by Amoe (Friar)
on Jun 14, 2003 at 21:49 UTC ( #265953=perlquestion: print w/ replies, xml ) Need Help??
Amoe has asked for the wisdom of the Perl Monks concerning the following question:

So in my endless quest for syntactic sugar, I discovered the standard Shell.pm module. This will make my random glue much more readable, thought I. So I tried it out, and it was good; even better when combined with autoquoting arrows (not demonstrated here for clarity). Trouble is, try as I might, I was unable to pass arguments with spaces to the spawned process: they were always seen as two separate arguments, no matter how much I escaped them.

use Shell qw(oggenc); # ("bar.wav" doesn't exist, so errors of the form "cannot open input f +ile # 'bar.wav' indicate the command is being parsed correctly. "Multiple + input # files" type errors indicate that the spaced argument is being seen a +s two.) # All the system() calls work... # ERROR: Cannot open input file "bar.wav": No such file or directory system("oggenc -o foo.ogg -c " . quotemeta("composer=J. Random Hacker" +) . " bar.wav"); # ERROR: Cannot open input file "bar.wav": No such file or directory system("oggenc", "-o", "foo.ogg", "-c", "composer=J. Random Hacker", " +bar.wav"); # None of the Shell.pm ones do. # ERROR: Multiple input files with specified output filename: suggest +using -n oggenc("-o", "foo.ogg", "-c", "composer=J. Random Hacker", "bar.wav"); # ERROR: Multiple input files with specified output filename: suggest +using -n oggenc("-o", "foo.ogg", "-c", quotemeta("composer=J. Random Hacker"), +"bar.wav"); # ERROR: Multiple input files with specified output filename: suggest +using -n oggenc("-o foo.ogg -c " . quotemeta("composer=J. Random Hacker") . " b +ar.wav");

Does anyone know how I can pass an argument with whitespace in it? If not, why, and is this to be construed as a bug or a feature? Thanks in advance. (Looking back, I have no idea why the first part of this node is written in the past tense. Nevermind.)

--
amoe

Comment on Shell.pm mangling arguments with embedded whitespace?
Download Code
Re: Shell.pm mangling arguments with embedded whitespace?
by PodMaster (Abbot) on Jun 15, 2003 at 05:51 UTC
    Try quoting instead of escaping them. You'll wanna look closer at `perldoc -f system' to grasp the nuances of the system call, and then you should open Shell.pm and look inside. If you do, you'll see that it's using the magic open (see perlopentut)

    While Shell.pm might offer some AUTOLOAD magic that appeals to you, I don't think you really want to use it (from the snippets you've shown, you're not doing anything the output of oggenc).

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://265953]
Approved by dorko
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (15)
As of 2014-12-18 18:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (59 votes), past polls