Reputation: 4273
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.
Upvotes: 8
Views: 11806
Reputation: 1
Check your full file location string.
I was having this problem, but it was only for a specific file, so I thought that it was something about that file. I had an ampersand in one of the parent directories, and the Padre client could not interpret the full file string. Be sure you full file location string does not have spaces or non-alpha-numeric characters.
Not fool-proof, but one pitfall to avoid.
Upvotes: 0
Reputation: 31
Add this line to the end of your program:
system("pause");
Windows will prompt with "Press any key to continue . . ."
Upvotes: 3
Reputation: 3601
print "Hello, world\n";
print "Press RETURN to continue ";
<STDIN>;
Upvotes: 3
Reputation: 994937
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>
Upvotes: 13