mercredi 9 septembre 2015

Batch "if" command, "if" multiple conditions are not met, perform an action

I tried to convey my intentions in the title, but basically this is "part" of my batch command:

set /p "choice=Enter an option: "
if %choice% == 1 GOTO Redo
if %choice% == 2 GOTO Remove
if %choice% == 3 GOTO Notice
if %choice% == 4 GOTO Cancel
if %choice% == 5 GOTO Exit

And any input that doesn't contain 1, 2, 3, 4, or 5 goto :error

I will also need the same function for inputs that aren't numbers, so using EQU, NEQ, GTR, LSS, etc. won't work for:

set /p "Option=Would you like to do ..., y/n?: "
if %Option% == n GOTO MainMenu
if %Option% == y GOTO Reroute

If not n or y, goto error.

I tested with if %errorlevel% NEQ 0 goto :error among others, to no avail.

What ends up happening is that it would just skip the next section of the batch, rather than going to :error

Thanks in advance for the help.

Aucun commentaire:

Enregistrer un commentaire