windows 如何在完成后阻止 Perl 程序关闭其窗口?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5607839/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 16:36:17  来源:igfitidea点击:

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

windowsperl

提问by Brian

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

在 Windows 中完成执行后,如何阻止我的 Perl 程序关闭窗口?

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

我可以运行一个 Hello World 程序,但它关闭得太快了,我无法真正阅读它。

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.

似乎是我能找到的唯一解决方案,但我打赌有更好的方法来做到这一点。

回答by Greg Hewgill

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:

从 Windows 命令提示符运行脚本,而不是单击资源管理器中的图标。当您通过单击图标运行控制台模式程序时,Windows 将为该程序打开一个窗口,运行它,然后关闭该窗口。当您从命令提示符运行控制台模式程序时,该窗口不会关闭:

C:\test> perl hello.pl
Hello World

C:\test>

回答by shawnhcorey

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

回答by Vern

Add this line to the end of your program:

将此行添加到程序的末尾:

system("pause");

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

Windows 将提示“按任意键继续...”

回答by GarrettML

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.

我遇到了这个问题,但它仅针对特定文件,所以我认为这是与该文件有关的问题。我在其中一个父目录中有一个&符号,而 Padre 客户端无法解释完整的文件字符串。确保您的完整文件位置字符串没有空格或非字母数字字符。

Not fool-proof, but one pitfall to avoid.

不是万无一失,而是要避免的一个陷阱。