China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-12 22:14
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Can a BAT file quit directly when Q is pressed without hitting Enter? View 1,238 Replies 3
Original Poster Posted 2009-06-03 11:12 ·  中国 江苏 南京 联通
新手上路
Credits 6
Posts 6
Joined 2009-04-11 22:45
17-year member
UID 142713
Gender Male
Status Offline
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!
Floor 2 Posted 2009-06-04 04:28 ·  中国 江苏 南京 电信
新手上路
Credits 6
Posts 6
Joined 2009-04-11 22:45
17-year member
UID 142713
Gender Male
Status Offline
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!
Floor 3 Posted 2009-06-04 05:06 ·  中国 四川 成都 双流区 电信
新手上路
Credits 1
Posts 1
Joined 2009-06-02 05:51
17-year member
UID 146512
Gender Male
Status Offline
@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
Floor 4 Posted 2009-11-30 03:14 ·  中国 天津 电信
初级用户
★★
Credits 128
Posts 122
Joined 2009-09-21 06:24
16-year member
UID 152378
Gender Male
Status Offline
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…
Forum Jump: