How to stop a Perl program after closing a window?

How can I stop a Perl program from closing a window after completion of execution on Windows?

I can run the Hello World Program, but for me it closes too quickly to actually read it.

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

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

+6
source share
4 answers

Run the script from the Windows command prompt, and do not click the icon in Explorer. When you start the console mode programs by clicking on the icon, Windows will open a window for the program, start it and close the window. When you start console mode programs from the command line, the window does not close:

  C: \ test> perl hello.pl
 Hello world

 C: \ test>
+12
source
 print "Hello, world\n"; print "Press RETURN to continue "; <STDIN>; 
+2
source

Add this line to the end of your program:

 system("pause"); 

Windows will offer "Press any key to continue."

+1
source

Check the complete file location string.

I had this problem, but it was only for a specific file, so I thought it was something in this file. I had an ampersand in one of the parent directories, and the Padre client was unable to interpret the full line of the file. Ensure that the complete file location string does not contain spaces or non-alphanumeric characters.

Not stupid, but one trap to avoid.

0
source

Source: https://habr.com/ru/post/885577/


All Articles