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

Not really a problem, but just to satisfy my curiosity: On Windows, the following commands work the same from the Windows command line:

perl -we "system('pause')" pause cmd /c pause
but the following does not:
perl -we "system('cmd /c pause')"
It says that the command 'pause' is not found. How come? PAUSE is, AFIK, an internal command of CMD.EXE, and doing a "cmd /c pause" from the command line works fine. Why does it not work when called from Perl via system()?

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re: Windows: system() and PAUSE
by Anonymous Monk on Apr 09, 2010 at 09:26 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';"

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

        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 . . .
Re: Windows: system() and PAUSE
by cdarke (Prior) on Apr 09, 2010 at 09:00 UTC
    Works for me, Windows XP:
    C:\>perl -we "system('cmd /c pause')" Press any key to continue . . .

    Update: also works on 64-bit Windows 7 from cmd.exe and PowerShell (ActiveState 5.10.1).
Re: Windows: system() and PAUSE
by ikegami (Patriarch) on Apr 09, 2010 at 08:59 UTC
    Works for me. ActiverPerl 5.6.0, 5.6.1, 5.8.0, 5.8.8, 5.10.0, 5.10.1

      Error occurs for me with ActivePerl 5.8.8, but not 5.10.0. I tested so far on Windows 2000. Will try to retest on other platforms too.

      -- 
      Ronald Fischer <ynnor@mm.st>