Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

embedded spaces in paths and system()

by rmlacey (Initiate)
on Feb 21, 2002 at 02:18 UTC ( #146681=perlquestion: print w/replies, xml ) Need Help??

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

This is a win32-centric (mostly) problem. I'm trying to invoke InstallShield programs (compile.exe and isbuild.exe actually, via bash) where there are numerous arguments for which some are paths for include directories and contain embedded spaces. The problem I'm having is getting the quoting of the strings correct so bash doesn't burp, and the pathing is correct. There must be an easier way to invoke a program where arguments have embedded spaces. Any ideas?

Replies are listed 'Best First'.
Re: embedded spaces in paths and system()
by particle (Vicar) on Feb 21, 2002 at 02:24 UTC
    send an array to system. (BTW, it's in the doc... see system)

    my @args = ( "compile.exe", "my silly windows directory", "file" ); my $rc = system( @args );


(tye)Re: embedded spaces in paths and system()
by tye (Sage) on Feb 21, 2002 at 05:11 UTC

    Unfortunately, Win32 only knows how to pass along command lines, not preparsed command-line arguments so multi-argument system doesn't do any good (it could be made to emulate that better, but that is another story). So you just have to put double quotes around any arguments that are paths that might include spaces and hope that the program being invoked follows this general practice and deals with such. If you are indeed throwing bash into the mix, then things probably get more complicated. I'd avoid that.

    Alternately you can convert to the "short" path name which would not contain any spaces:

    use Win32; my $short= Win32::GetShortPathName($long);

            - tye (but my friends call me "Tye")
Re: embedded spaces in paths and system()
by Zaxo (Archbishop) on Feb 21, 2002 at 02:21 UTC
      There is very little common in 'quote regular expression magic characters' (from description of quotemeta) and proper usage of system.

      Ilya Martynov (

      quotemeta should work if InstallShield weren't so stupid. It seems that InstallShield can't parse paths with forward slashes in them. The major problem here is that I've got qouted strings inside qouted strings.
Re: embedded spaces in paths and system()
by strat (Canon) on Feb 21, 2002 at 13:13 UTC
    Sometimes it also helps to put "..." around...
    my $path = q~"c:\eigene Dateien\anything"~; print `dir $path`;

    Best regards,

    perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://146681]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2023-02-02 02:02 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (15 votes). Check out past polls.