DOS batch command

E

Eric

Hello,

Is there a command like the "old" choice command that would allow me to
build and interactive batch file?

Thank you.

Eric.
 
S

Shenan Stanley

Eric said:
Is there a command like the "old" choice command that would allow
me to build and interactive batch file?

Yes.

Choice.
However - for stability reasons - it was removed. It does work.

Innately - use the "set" command.
Use "set /?" to see a list of options.

For example:
-----
@echo off
REM ---------------------------------------------------------------------------------
REM | sample batch file using the SET command
|
REM | at the bottom where the echo commands tell the user what choice they
made |
REM | you can add anything you want, including multiple commands
|
REM ---------------------------------------------------------------------------------
cls
:start
echo.
echo. You have 3 choices:
echo.
echo 1. enter option 1 here
echo 2. enter option 2 here
echo 3. enter option 3 here

REM Clear the Environment variable, "choice"
set choice=

REM Tell user to enter choice, and assign it to the "choice" Variable
set /p choice=Enter your choice now :
REM strip all but the first char from the content of var choice.
REM the :~0,1 means return from offset zero (aka begin one character)
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto CHOICE1
if '%choice%'=='2' goto CHOICE2
if '%choice%'=='3' goto CHOICE3
echo "%choice%" is not valid please try again
echo.
goto start

REM act on the choice that the User made
:CHOICE1
echo You entered 1
goto end
:CHOICE2
echo You entered 2
goto end
:CHOICE3
echo You entered 3

:end------- Shenan Stanley MS-MVP-- How To Ask Questions The Smart
Wayhttp://www.catb.org/~esr/faqs/smart-questions.html
 
E

Eric

Worked like a charm!
Thank you Shenan..

Eric.

Shenan Stanley said:
Yes.

Choice.
However - for stability reasons - it was removed. It does work.

Innately - use the "set" command.
Use "set /?" to see a list of options.

For example:
-----
@echo off
REM ---------------------------------------------------------------------------------
REM | sample batch file using the SET command |
REM | at the bottom where the echo commands tell the user what choice they
made |
REM | you can add anything you want, including multiple commands |
REM ---------------------------------------------------------------------------------
cls
:start
echo.
echo. You have 3 choices:
echo.
echo 1. enter option 1 here
echo 2. enter option 2 here
echo 3. enter option 3 here

REM Clear the Environment variable, "choice"
set choice=

REM Tell user to enter choice, and assign it to the "choice" Variable
set /p choice=Enter your choice now :
REM strip all but the first char from the content of var choice.
REM the :~0,1 means return from offset zero (aka begin one character)
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto CHOICE1
if '%choice%'=='2' goto CHOICE2
if '%choice%'=='3' goto CHOICE3
echo "%choice%" is not valid please try again
echo.
goto start

REM act on the choice that the User made
:CHOICE1
echo You entered 1
goto end
:CHOICE2
echo You entered 2
goto end
:CHOICE3
echo You entered 3

:end------- Shenan Stanley MS-MVP-- How To Ask Questions The Smart
Wayhttp://www.catb.org/~esr/faqs/smart-questions.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top