in reply to Executing a Dos command

You double click on the perl script, a window opens, the results flash by, the window closes?

You want the window to stay open so you can read the output?

If that is the case something like this will do it.

#!/usr/bin/perl use strict; use warnings; # do something print "results\n"; # do something else print "more results\n"; system('dir'); print "done. hit return\n"; <>;
The <> waits for input from STDIN (the keyboard in this case) and will prevent the window closing.

Replies are listed 'Best First'.
Re^2: Executing a Dos command
by TGI (Parson) on Aug 11, 2007 at 21:27 UTC

    You've got to be careful with <>, because it will also process command line arguments, which can lead to unexpected errors.

    C:\>perl -e "<>;" -- foo Can't open foo: No such file or directory at -e line 1.

    If a file named 'foo' actually exists, then a line would will be read from it, and the script will disappear as if this step was never taken.

    I usually use <STDIN>; or if I am reliving my old habit of batch scripting, `pause`;. The pause approach will continue after any key press, not just 'ENTER', but it does spawn a shell. Choose your poison.


    TGI says moo