Home > front end >  how can i show a misinput in CMD?
how can i show a misinput in CMD?

Time:02-24

i been doing a menu for my class in cmd and i cant make something like a if else structure for it , so even if i give him a wrong input it wont even show a message on the screen, someone know what i can do in this ?

ECHO OFF
CLS
:MENU
ECHO.
ECHO ...............................................
ECHO presione su eleccion :1,2 o 3 para salir
ECHO ...............................................
ECHO.
ECHO 1 - Copia de seguridad y ruta de guardado del respaldo 
ECHO 2 - Cambio de extension de un archivo
ECHO 3 - Salir
ECHO.
ECHO.
SET /P M=presione 1,2 o 3 y presione enter:
IF %M%==1 (GOTO RESPALDO)
ELSE IF %M%==2 (GOTO EXTENSION)
ELSE IF %M%==3 (GOTO EOF)
ELSE (ECHO Opcion no valida 
GOTO MENU)

:RESPALDO
cd %windir%\system32\notepad.exe
start notepad.exe
GOTO MENU
:EXTENSION
cd %windir%\system32\calc.exe
start calc.exe
GOTO MENU

CodePudding user response:

The ELSE must be in the "same" line as the IF (maybe extended by parenthesis ()). So you could write something like this:

IF %M%==1 (GOTO RESPALDO) else (
IF %M%==2 (GOTO EXTENSION) else (
IF %M%==3 (GOTO :EOF) else (
ECHO Opcion no valida 
GOTO MENU
)
)
)

But in this example, you could also dismiss the ELSE:

IF %M%==1 (GOTO RESPALDO)
IF %M%==2 (GOTO EXTENSION)
IF %M%==3 (GOTO :EOF)
ECHO Opcion no valida 
GOTO MENU

BTW: The GOTO :EOF must have the colon, if not it is not found.

  • Related