Reputation: 7605
ECHO OFF
CLS
:MENU
ECHO.
ECHO ...............................................
ECHO PRESS 1 or 2 to select your task, or 4 to EXIT.
ECHO ...............................................
ECHO.
ECHO 1 - Test
ECHO 2 - Production
ECHO 4 - EXIT
ECHO.
CHOICE /C:124
IF ERRORLEVEL 1 SET M=1
IF ERRORLEVEL 2 SET M=2
IF ERRORLEVEL 4 SET M=4
IF %M%==1 GOTO TEST
IF %M%==2 GOTO PROD
IF %M%==4 GOTO EOF
:TEST
ECHO TEST
cd %~dp0\Test\
start Test.exe
GOTO MENU
:PROD
ECHO PROD
cd %~dp0\Production\
start Production.exe
GOTO MENU
no matter which option is selected, it's always launching Test.exe
What am i doing wrong?
Upvotes: 0
Views: 42
Reputation: 21505
This appears to work:
ECHO OFF
CLS
:MENU
ECHO.
ECHO ...............................................
ECHO PRESS 1 or 2 to select your task, or 4 to EXIT.
ECHO ...............................................
ECHO.
ECHO 1 - Test
ECHO 2 - Production
ECHO 4 - EXIT
ECHO.
CHOICE /C:124
IF %ERRORLEVEL% EQU 1 SET M=1
IF %ERRORLEVEL% EQU 2 SET M=2
IF %ERRORLEVEL% EQU 3 SET M=4
IF %M% EQU 1 GOTO TEST
IF %M% EQU 2 GOTO PROD
IF %M% EQU 4 GOTO EOF
:TEST
ECHO TEST
cd %~dp0\Test\
ECHO start Test.exe
GOTO MENU
:PROD
ECHO PROD
cd %~dp0\Production\
start Production.exe
GOTO MENU
:EOF
A couple of minor changes to your script required
%ERRORLEVEL%
variable rather than using IF ERRORLEVEL
CHOICE
returns the index of the selected option, not the selected value - 4
is the third option and so has the index 3.Upvotes: 2