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

I've read perlmonks a lot recently, but this is the first time I have ever posted here (Hooray for the lurkers!). I ran into a problem that has me kind of stumped. Basically, I am automating a build process for win2k in MS Embedded C++ using activestate perl, and I am having issues with multiple sets of quotation marks. Here's the relevant code:
my $proggie = '"C:\Program Files\Microsoft eMbedded Tools\Common\EVC\B +in\EVC.EXE"'; my $switch = ' /MAKE "Project - Win32 Debug"'; print $proggie . "\n"; system $proggie; print $proggie . $switch . "\n"; system $proggie . $switch; '"C:\Program Files\Microsoft eMbedded Tools\Common\EVC\Bin\EVC.EXE" /M +AKE "Project - Win32 Debug"';
The issue is in the last two lines (6 and 7). Line 4 starts up the program beautifully by itself, as expected. Line 5 prints out what I think system() should be sending to the command line. And line 6 returns this error: 'C:\Program' is not recognized as an internal or external command, operable program or batch file. Which of course has me baffled because I have not altered the path to $proggie in any way, I just added a switch with quotation marks. Line 7 returns the same error (It is what line 5 prints out, enclosed in backticks), but if I cut and paste the contents of line 7 (Ignoring the backticks of course) into the command line directly, it works beautifully. What the heck is going on? Is this a bug, or am I missing something? Ivar

Replies are listed 'Best First'.
(bbfu) Re: Win32 System() Weirdness
by bbfu (Curate) on Aug 16, 2001 at 06:42 UTC

    You might try leaving off the double-quotes in $proggie and using the PROGRAM LIST version of system, since it cuts out the shell and executes the program directly (which, I believe, is what is causing your problem).

    So your code would become (roughly):

    my $proggie = 'C:\Program Files\Microsoft eMbedded Tools\Common\EVC\Bi +n\EVC.EXE'; my @switches = ('/MAKE', 'Project - Win32 Debug'); system($proggie, @switches);

    Note that this is untested. Hope it helps.

    bbfu
    Seasons don't fear The Reaper.
    Nor do the wind, the sun, and the rain.
    We can be like they are.

Re: Win32 System() Weirdness
by John M. Dlugosz (Monsignor) on Aug 16, 2001 at 08:19 UTC
    To see what's really happening behind the curtain, change an env variable -- it's called PERLSHELL or something like that, but it ignores the usual COMSPEC -- to point to a stub that just prints argv's in main. Might also call GetCommandLine (something like that, Win32 API call) to see what it looked like before the standard library parsed it into words, and see where your quotes (still) were.

    I suspect that quotes may be getting lost.

    It's working fine for me, with ActiveState build 628, with the line:

    system '"C:\Program Files\Utilities\DskBench.exe" x y z' or die "$! $ +^E";
    This is Win2K. Maybe Win9x w/Command.COM has problems, I don't know.

    If all else fails, as a work-around use the short-name alias for the long directory names.

    Hmm... playing around with it more, I found that it fails if there is another set of quotes!!

    system '"C:\Program Files\Utilities\DskBench.exe" x y "foo z"' or die + "$! $^E";
    fails as you note.

    I have a dim memory of a case where I couldn't get system to work right, and ended up spitting out a batch file and running that.

    It is clearly a bug somewhere in the system processing. If you do tests like I suggested above, you might find that the presense of more quotes makes them all stripped, or something like that.

    —John

Re: Win32 System() Weirdness
by Anonymous Monk on Aug 16, 2001 at 21:14 UTC
    bbfu was correct. It seems when you call the program list version of system(), it works fine, but it is unhappy with just a single string. My guess is that it is stripping the quotes for some reason (as opposed to adding a second set around the whole string), based on playing around with adding and removing quotes in the string to no effect.

    Thanks for your help!

    Ivar