How to stop a Perl program from closing its window when it is finished?

11,188

Solution 1

Run your script from the Windows command prompt, instead of clicking on an icon in Explorer. When you run console mode programs from clicking on an icon, Windows will open a window for the program, run it, then close the window. When you run console mode programs from a command prompt, the window won't close:

C:\test> perl hello.pl
Hello World

C:\test>

Solution 2

print "Hello, world\n";
print "Press RETURN to continue ";
<STDIN>;

Solution 3

Add this line to the end of your program:

system("pause");

Windows will prompt with "Press any key to continue . . ."

Share:
11,188
Brian
Author by

Brian

Updated on June 18, 2022

Comments

  • Brian
    Brian almost 2 years

    How can I stop my Perl program from closing the window after finishing execution in windows?

    I can run a Hello World Program, but it closes way too quick for me to actually read it.

    print "Hello World\n";
    while (1){sleep(1)}
    

    Seems to be the only solution I could find, but I'm betting there is a better way to do this.

    • ajwood
      ajwood about 13 years
      How are you executing your program? Are you not doing it directly from a command line?