3

I would like to build script to chose commands to run but then they should run in a specific order which was set at the beginning by user. for example:

:MENU
ECHO.

SET /P M=Type 1, 2, 3, 4 or 5 then press ENTER:
IF %M%==1 GOTO 1
IF %M%==2 GOTO 2
IF %M%==3 GOTO 3
IF %M%==4 GOTO 4
IF %M%==5 GOTO 5

:1
GOTO MENU

:2
GOTO MENU

:3
GOTO MENU

:4
GOTO MENU

:5
EXIT

For example in this scenario when I am prompt to choose 1, 2, 3, 4 or 5 I would like to execute command: 1, 2, 4 then display MENU. So I simply type 1, 2, 4 on the screen and then batch will execute it - Commands should follow order 1 then 2 then 4

The other example would be 1, 3, 2, 4 etc.

is this possible? :)

1 Answer 1

3
:MENU
ECHO.

SET /P M=Type 1, 2, 3, 4 or 5 then press ENTER:


for %%C in (%M%) do (
 call :%%C
)
goto :MENU    

:1
GOTO :EOF

:2
GOTO :EOF

:3
GOTO :EOF

:4
GOTO :EOF

:5
EXIT

I'm not absolutely sure if this is what you looking for..

Sign up to request clarification or add additional context in comments.

6 Comments

nope :), ok, example 1 User input: 1, 2, 3. Script executes command from 1, 2 and 3.
Example 2: User input: 2, 1, 4, 1. Script executes command from 2, 1, 4 and again 1.
this will do the same if the input is 2,1,4,1<Enter>
@MartinM - The code is just missing a GOTO MENU after the closure of the FOR loop.
+1 It will work well - I edited the code and added the goto :menu as @dbenham mentioned.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.