中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-12 21:19
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » [Help] Can a BAT file quit directly when Q is pressed without hitting Enter?
Printable Version  1,237 / 3
Floor1 fantasybb Posted 2009-06-03 11:12
新手上路 Posts 6 Credits 6
I've searched through all the forum posts and still couldn't find this question. It should be possible, right? I seem to remember seeing P used like this before.
Let me explain again: for example, when a batch file runs to pause, if there are no more statements after it, it will prompt “Press any key to continue...”. At that point, press any key and this P closes.
How can this be done? Thanks!
Floor2 fantasybb Posted 2009-06-04 04:28
新手上路 Posts 6 Credits 6
Bumping this myself.
What I want is for it to quit directly only when Q is pressed. If anything else is entered, ignore it.
Is this impossible? If any experienced member can confirm that it can't be done, please let me know too, thanks!
Floor3 fydxy Posted 2009-06-04 05:06
新手上路 Posts 1 Credits 1
@echo off
echo. Now press q and it can quit~~~
choice /c:q/n >nul 2>nul
exit
Add it to the last line and pressing q will make it quit
Floor4 jarry0932 Posted 2009-11-30 03:14
初级用户 Posts 122 Credits 128
Originally posted by fydxy at 2009-6-4 05:06:
@echo off
echo. Now press q and it can quit~~~
choice /c:q/n >nul 2>nul
exit
Add it to the last line and pressing q will make it quit

There is no choice command anymore, so how do you use it?
As for the OP wanting it to quit only by pressing q and without hitting Enter, if you ask me, that can't be done. You can only do it like this:
@echo off
echo Press q to quit…
pause>nul
Fool yourself a bit, and it looks like pressing q quits it…
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023