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-07-06 14:01
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » About the choice command View 3,954 Replies 17
Floor 16 Posted 2004-06-25 00:00 ·  中国 湖南 长沙 电信
初级用户
Credits 138
Posts 6
Joined 2003-08-01 00:00
22-year member
UID 7894
Gender Male
Status Offline
CHOICE: The CHOICE command. This is a DOS external command, but it is mainly used in batch files.

After the CHOICE command is executed, it will prompt for selectable items, and then select by pressing a key.

Usage: CHOICE key list] selected value, seconds]
Among them, /C means selectable keys, /N means not to display the prompt information, /S means case-sensitive mode, /T means if there is no selection within the specified time, automatically execute a certain selection value defined in /C. The prompt text is the prompt information when the CHOICE command is executed. The selection result will be represented by the ERRORLEVEL value.

IF ERRORLEVEL error return code command
Meaning: If the error return code is greater than or equal to the specified code, a certain command will be executed.
Among them, ERRORLEVEL represents the error return code, which is very useful. For many DOS commands, due to different execution results (such as successful execution, failed execution, or interrupted by the user, etc.), these commands will return different codes to indicate different results. The IF ERRORLEVEL command executes different commands according to the different codes generated by this different result, and is usually used after a certain command. For example, IF ERRORLEVEL 1 ECHO OK! means that if the current error return code is greater than or equal to 1, the words "OK!" will be displayed on the screen
****DOS****DOS****
Floor 17 Posted 2009-04-04 00:41 ·  中国 辽宁 鞍山 联通
初级用户
Credits 43
Posts 24
Joined 2009-04-03 07:29
17-year member
UID 142006
Gender Male
Status Offline
Here's the translation: Give you a piece of code, you try it yourself! choice /c:yn /t:n,5 yes, no,
Floor 18 Posted 2009-09-17 03:31 ·  马来西亚
初级用户
Credits 70
Posts 33
Joined 2009-09-15 13:28
16-year member
UID 152067
Gender Male
Status Offline
But Windows XP doesn't have this function anymore!

choice is only available in: MS-DOS 6.0+, Windows 95, Windows 98, Windows Vista, Windows 7!!!




Windows XP uses set,
Here's a piece of code for you to try it yourself! !!!!
Just understand it yourself!!!

@ECHO off
cls
:start
ECHO.
ECHO 1. Print Hello
ECHO 2. Print Bye
ECHO 3. Print Test
set choice=
set /p choice=Type the number to print text.
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto hello
if '%choice%'=='2' goto bye
if '%choice%'=='3' goto test
ECHO "%choice%" is not valid please try again
ECHO.
goto start
:hello
ECHO HELLO
goto end
:bye
ECHO BYE
goto end
:test
ECHO TEST
goto end
:end
Forum Jump: