InterviewSolution
| 1. |
Solve : Batch scripting help? |
|
Answer» I'm trying to write a batch file that will display a list to the user, have them enter their choice, and then do something. Here's what I have now: echo %errorlev%' always prints 1. There is a reason for this. Errorlevel 1 means "errorlevel 1 or greater" so the test will always be true, so gotos are needed if 3 or 2 are chosen @echo off echo 1. BL (main) echo 2. BL (sound) echo 3. MS-DOS choice /C:123 /N if errorlevel 3 goto choice3 if errorlevel 2 goto choice2 if errorlevel 1 goto choice1 :choice3 echo you chose 3 goto next :choice2 echo you chose 2 goto next :choice1 echo you chose 1 :next Sorry, I had a brain malfunction... Reverse the order of the IF statements to be 1 2 3 not 3 2 1 Here's another version with a couple of embellishments: Code: [Select]@echo off cls echo. echo. echo 1. BL (main) echo 2. BL (sound) echo 3. MS-DOS echo. echo. choice /C:123 /N " Enter your choice..... " cls if errorlevel 1 set errorlev=1 if errorlevel 2 set errorlev=2 if errorlevel 3 set errorlev=3 echo. echo. echo Return Code = %errorlev% Hope that fixes it.Great, that worked. Thanks!You're welcome & again sorry about giving you FALSE INFO to start with. Good luck |
|