in reply to Win32 spaces in path, open Excel w/ 'system' and glob/DosGlob


You can escape the backslashes using quotemeta:
#!/usr/bin/perl -wl my $str = 'C:\Program Files\Microsoft Office\Office\Excel.exe'; $str = quotemeta $str; print $str; __END__ prints: C\:\\Program\ Files\\Microsoft\ Office\\Office\\Excel\.exe

Or convert the backslashes to forward slashes:

$str =~ s[\\][/]g;

--
John.

Replies are listed 'Best First'.
Re: Re: Win32 spaces in path, open Excel w/ 'system' and glob/DosGlob
by ff (Hermit) on Oct 23, 2003 at 12:35 UTC
    Thanks John, it appears that quotemeta will do the trick.

    Using the forward slash approach works if there are no spaces but my memory says that glob would then treat the space as an IFS character and not use the whole command string for Win32 to see when invoking system. Portions after the space would be treated as arguments for the (now bogus) command before the space.

    Brig

    (re "my memory says": I developed this portion of my app SEVERAL months ago and am trying to resolve interface issues like this before I release to a wider circle of users.... :-)

    Update: My memory also says that, as a fan of File::Spec and catfile, I was sorely disappointed when I couldn't finagle a way to get its output to work well when invoked by system, again plagued by system losing something in the translation: Win32 did not like being passed a command whose absolute path name included forward slashes. I believe that the embedded spaces were difficult, too....

    Perhaps I should go get some fresh complaints (test results) from using File::Spec output....