简体   繁体   English

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

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

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. 似乎是我能找到的唯一解决方案,但我认为有更好的方法可以做到这一点。

Run your script from the Windows command prompt, instead of clicking on an icon in Explorer. 从Windows命令提示符运行脚本,而不是单击资源管理器中的图标。 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. 当您通过单击图标运行控制台模式程序时,Windows将打开该程序的窗口,运行它,然后关闭窗口。 When you run console mode programs from a command prompt, the window won't close: 从命令提示符运行控制台模式程序时,窗口将不会关闭:

C:\test> perl hello.pl
Hello World

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

Add this line to the end of your program: 将此行添加到程序的末尾:

system("pause");

Windows will prompt with "Press any key to continue . . ." Windows将提示“按任意键继续...”。

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. 我在其中一个父目录中有一个&符号,而Padre客户端无法解释完整的文件字符串。 Be sure you full file location string does not have spaces or non-alpha-numeric characters. 确保完整文件位置字符串没有空格或非字母数字字符。

Not fool-proof, but one pitfall to avoid. 不是万无一失,但要避免一个陷阱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM