Accept user input to a batch file. Choice allows single key-presses to be captured from the keyboard.

 CHOICE [/c [choiceKeys]] [/N] [/CS] [/t Timeout /d Choice] [/m Text]key /C[:]choiceKeys : One or more keys the user can press. Default is YN. /N : Do not display choiceKeys at the end of the prompt string. /CS : Make the choiceKeys Case Sensitive. /T Timeout : Timeout in Timeout seconds If Timeout is 0 there will be no pause and the default will be selected. /d choice  : Default choice made on Timeout. /m text : Message string to describe the choices available.

ERRORLEVEL will return the numerical offset of choiceKeys.
Choice.exe is a standard command in Windows 2003, Vista and Windows 7 (for XP you can use the early resource kit versions).

Early versions of (not Choice.exe) burn a lot of CPU’s when in a wait state, plus there are some issues where multiple concurrent invocations will clobber each other.


CHOICE /C CH /M Select [C] CD or [H] Hard drive
IF errorlevel 2 goto sub_hard
IF errorlevel 1 goto sub_cd

The order of the IF statements above matters, IF errorlevel 1 will return TRUE for an errorlevel of 2

CHOICE can be used to set a specific %errorlevel%
for example to set the %errorlevel% to 6 :
ECHO 6| CHOICE /C 123456 /N >NUL

“If you limit your choices only to what seems possible or reasonable, you disconnect yourself from what you truly want, and all that is left is compromise” – Robert Fritz


IF – Conditionally perform a command
SET /P – Prompt for user input (accepts a whole string instead of one keypress)
PowerShell: Read-Host – Read a line of input from the console.
Equivalent bash command (Linux): case / select – Accept keyboard input

« Back to Glossary Index