in reply to Windows: system() and PAUSE

command not found cmd.exe site:perlmonks.org: Re^2: system command can't spawn cmd.exe:
$ perl -we" system qw[ C:\WINDOWS\system32\cmd.EXE /c pause ];" Press any key to continue . . .

Replies are listed 'Best First'.
Re^2: Windows: system() and PAUSE
by rovf (Priest) on Apr 09, 2010 at 10:04 UTC
    Indeed, this worked (I just had to adjust the path, since I'm running Windows 2000):

    >perl -we "system qw[ C:\WINNT\system32\cmd.EXE /c pause ];" Drücken Sie eine beliebige Taste . . . >perl -we "system qw[ cmd /c pause ];" Der Befehl "pause"" ist entweder falsch geschrieben oder konnte nicht gefunden werden.

    This is really weird. It applies to all internal commands, while external ones work well even without specifying a path:
    >perl -we "system qw[ cmd /c ls.exe ];" ....
    I really would like to know what's going on here....
    -- 
    Ronald Fischer <ynnor@mm.st>

      Which build of AS?

      Out of curiosity, which of the following work?

      perl -we"system qw[ cmd /c pause ];" perl -we"system qw[ cmd.exe /c pause ];" perl -we"system 'cmd /c pause';"
        Which build of AS?
        This is perl, v5.8.8 built for MSWin32-x86-multi-thread (with 18 registered patches, see perl -V for more detail) Copyright 1987-2007, Larry Wall Binary build 822 280952 provided by ActiveState http://www.ActiveState.com Built Jul 31 2007 19:34:48
        perl -we"system qw cmd /c pause ;"
        Does not work.
        perl -we"system qw cmd.exe /c pause ;"
        Works.

        AHA!!!!!

        But I checked my PATH, and there is only cmd.exe in the PATH, no cmd.bat, cmd.com, cmd.cmd .... And I changed my PATH so that it only contained the Perl bin directory, and C:\WINNT\system32, and the error still occurs.
        perl -we"system 'cmd /c pause';"
        Does not work.

        -- 
        Ronald Fischer <ynnor@mm.st>
      Maybe you have another version of cmd.exe in your path? Try using %comspec% - that works for me on Windows XP and 7.
      C:\>perl -we "system('%comspec% /c pause')" Press any key to continue . . .
        Maybe you have another version of cmd.exe in your path?
        No, only one. Checked with WO.EXE.

        -- 
        Ronald Fischer <ynnor@mm.st>

      Does c:\WINNT\system32 appear in your path?

        Does c:\WINNT\system32 appear in your path?
        Yes, otherwise system('cmd /c ls.exe') and system('pause') wouldn't work either; plus, I would get an error message saying that CMD is not found.

        -- 
        Ronald Fischer <ynnor@mm.st>