Use environment variables for user input in Windows NT

It can be useful sometimes to provide the user with a choice when running batch file from the command prompt (cmd.exe). This can be done with this command that prompts the user for input from the console and saves it in an environment variable:

:choice
set /p your_choice="Please enter your choice (1,2,3): "
if %your_choice%==3 goto option3
if %your_choice%==2 goto option2
if %your_choice%==1 goto option1
echo Unrecognized option: %your_choice%
goto choice

:option3
echo 3
goto exit

:option2
echo 2
goto exit

:option1
echo 1
goto exit

:exit
set your_choice=

Updated: 23 September 2007

Comments:

  1. Doug says:

    This was just what i needed to complete my batch script, thanks

Leave a Reply

Your email address will not be published. Required fields are marked *