|
Answer» I'm making a batch file that requires user input, but I can't get it to work
I'm using WINDOWS XP, but I don't think it makes a difference.
Here's what I have: CODE: [Select]:MainScreen echo. echo Options echo 1) Kill a task (program) echo 2) Start a task (program) echo 3) Restart echo 4) Shutdown echo 5) Logoff echo 6) Open taskmanager echo 7) Close echo. echo Type the number of the options you want to run then hit ENTER. set /p %MSC% = { if "%MSC%"=="1" GOTO KillTask if "%MSC%"=="2" goto StartTask if "%MSC%"=="3" goto Restart if "%MSC%"=="4" goto Shutdown if "%MSC%"=="5" goto Logoff if "%MSC%"=="6" goto Taskman if "%MSC%"=="7" goto Close else goto MainScreen
But when I run it no matter what number I type it sends me to the next section of code. Can someone please tell me how to fix the IF command?Try this: Code: [Select]:MainScreen echo. echo Options echo 1) Kill a task (program) echo 2) Start a task (program) echo 3) Restart echo 4) Shutdown echo 5) Logoff echo 6) Open taskmanager echo 7) Close echo. echo Type the number of the options you want to run then hit ENTER. set /p MSC= if "%MSC%"=="1" goto KillTask if "%MSC%"=="2" goto StartTask if "%MSC%"=="3" goto Restart if "%MSC%"=="4" goto Shutdown if "%MSC%"=="5" goto Logoff if "%MSC%"=="6" goto Taskman if "%MSC%"=="7" goto Close goto MainScreen It works, thanks soooooo much In case you didn't pick up on the problem, when you typed 'set /p %MSC% = {' you were trying to refer to a string that didn't exist. If you have used c/c++/etc. you may remember commands like 'int a' or w/e to DECLARE your verable. In DOS, when you surround charictors with % you are telling it to replace that text with whatever the string is equal to. Because you had not set a value to %MSC% it would replace it with nothing, so the program would run 'set /p = {' which does not respond to anything in the rest of your program.
Thank you for listening to the youngman's rant.If you wanted to keep the "{" at the end you just put "^" in front of it.
Code: [Select]:MainScreen echo. echo Options echo 1) Kill a task (program) echo 2) Start a task (program) echo 3) Restart echo 4) Shutdown echo 5) Logoff echo 6) Open taskmanager echo 7) Close echo. echo Type the number of the options you want to run then hit ENTER. set /p %MSC% = ^{ if "%MSC%"=="1" goto KillTask if "%MSC%"=="2" goto StartTask if "%MSC%"=="3" goto Restart if "%MSC%"=="4" goto Shutdown if "%MSC%"=="5" goto Logoff if "%MSC%"=="6" goto Taskman if "%MSC%"=="7" goto Close else goto MainScreen
|