使程序退出时不关闭 Windows 批处理文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1291884/
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
Make windows batch file not close upon program exit
提问by Claudiu
When the program is over, I want it to say "Press any key to continue..." so I can scroll thru the output.
当程序结束时,我希望它说“按任意键继续...”这样我就可以滚动输出。
回答by TheJacobTaylor
I believe you are looking for the command "pause". It should ask you to press any key.
我相信您正在寻找“暂停”命令。它应该要求您按任意键。
You can even appear to change the prompt. Instead of just using the pause statement, you can:
您甚至可以出现更改提示。除了使用 pause 语句,您还可以:
echo "Your message here"
pause > nul
This gets rid of the original pause message and inserts yours.
这将摆脱原始的暂停消息并插入您的暂停消息。
Jacob
雅各布
回答by Mohammad Anini
In Windows/DOS batch files:
在 Windows/DOS 批处理文件中:
pause
This prints a nice Press any key to continue . . .
message
这会打印一条不错的Press any key to continue . . .
消息
Or, if you don't want to show anything message, do this instead:
或者,如果您不想显示任何消息,请改为执行以下操作:
pause >nul
回答by Rodrigo
Create a shortcut to your batch file.
创建批处理文件的快捷方式。
Right click on the file and select "Properties".
右键单击该文件并选择“属性”。
In the tab "Shortcut" is the target, something like this:
在选项卡中,“快捷方式”是目标,如下所示:
C:\folder\file.bat
C:\文件夹\文件.bat
Change it by this one:
改成这个:
C:\Windows\System32\cmd.exe /K "C:\folder\file.bat"
C:\Windows\System32\cmd.exe /K "C:\文件夹\file.bat"
where "C:\Windows\System32" is the folder where cmd.exe is located, which may be another according to your Windows installation.
其中“C:\Windows\System32”是 cmd.exe 所在的文件夹,根据您的 Windows 安装可能是另一个文件夹。
Then you can run the shortcut.
然后就可以运行快捷方式了。
回答by Anand Shah
A part of me says that "pause" in the batch file should also do the trick. But also give the /K switch a try as well.
我的一部分说批处理文件中的“暂停”也应该可以解决问题。但也可以试试 /K 开关。
HTH
HTH
回答by Zombie Stephen
you need to type in pause, which when you make it to the end, it should say
你需要输入暂停,当你走到最后时,它应该说
Press any key to continue . . .
按任意键继续 。. .
but only if you put it at the end, because if you don't, it will pause it at the place you put it. Don't try '/k' because it doesn't work
但前提是你把它放在最后,因为如果你不这样做,它会在你放的地方暂停。不要尝试'/k',因为它不起作用
回答by Nitin
If you want the console to remain open, you can add the following at the end of batch file -
如果您希望控制台保持打开状态,您可以在批处理文件的末尾添加以下内容 -
call cmd
调用命令
This will open console with in the same one with all your environment variables set in your batch file and you can work in it.
这将打开控制台,并在批处理文件中设置所有环境变量,您可以在其中工作。