Using Choice to get user interaction

1 March 2002 by Snakefoot | Comment » | Trackback Off
MS DOS 6.0 introduced the program CHOICE, which can display a set of options and wait for the user to make a choice. When the user makes a selection the return code of CHOICE contains the selection, which can be accessed using ERRORLEVEL. This makes it possible to prompt the user for input from the command line in a batch file and react to it.

choice /c:abc Choose an option
IF ERRORLEVEL 3 GOTO OPTIONC
IF ERRORLEVEL 2 GOTO OPTIONB
IF ERRORLEVEL 1 GOTO OPTIONA

:OPTIONC
ECHO C
GOTO EXIT

:OPTIONB
ECHO B
GOTO EXIT

:OPTIONA
ECHO A
GOTO EXIT

:EXIT

More Info MS KB Q77457
More Info MS KB Q96697
More Info MS KB Q97504

Updated: 23 September 2007

Leave a comment


NB! Use the Forum for computer help and off-topic questions.

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>