set /p command problem

January 14, 2011 at 20:50:55
Specs: Windows 7
Hi, I am trying to make a simple batch file but I am frustrated about the problem below.
Just in case, I have only begun to make batch files so please do not post rude answers.
@echo off
:command
echo.==================
echo.1.HEY-echo hey
echo.2.PAUSE-pause
echo.==================

set /p command="What do you want to do? "
if %command%=="HEY" goto :echo
if %command%=="PAUSE" goto :com

:echo
echo.You chose to echo "HEY"
pause
goto :command

:com
echo.You chose to pause.
pause
goto :command

Now I was able to adapt an example from the internet.
But I face a problem when I have multiple "if" statements, for instance:
If i chose "HEY", it works fine as it echoes hey.
But when I choose PAUSE, it echoes hey again.
Please help me fix this problem.
Thanks in advance,
executable19


See More: set /p command problem

Report •

#1
January 14, 2011 at 21:08:38
try this you are putting too much stuff in ur code
:command
echo.==================
echo.1.HEY-echo hey
echo.2.PAUSE-pause
echo.==================

set /P command=What do you want to do?
if %command%==hey goto echo
if %command%==PAUSE goto com

:echo
echo You chose to echo "HEY"
pause
goto command

:com
echo You chose to pause.
pause
goto command


Report •

#2
January 14, 2011 at 21:09:28
Correction sorry

try this you are putting too much stuff in ur code
:command
echo ==================
echo 1.HEY-echo hey
echo 2.PAUSE-pause
echo ==================

set /P command=What do you want to do?
if %command%==hey goto echo
if %command%==PAUSE goto com

:echo
echo You chose to echo "HEY"
pause
goto command

:com
echo You chose to pause.
pause
goto command


Report •

#3
January 14, 2011 at 21:13:57
@echo off
:input
echo.==================
echo.1.HEY-echo hey
echo.2.PAUSE-pause
echo.==================

set command=
set /P command=What do you want to do?
if not defined command goto input
if "%command:"=%"=="" goto input
if /i "%command:"=%"=="hey" goto echo
if /i "%command:"=%"=="PAUSE" goto com
goto input

:echo
echo You chose to echo "HEY"
pause
goto input

:com
echo You chose to pause.
pause
goto input


Report •

Related Solutions

#4
January 14, 2011 at 22:37:48
Thanks Rocky, and Judago. It really helped me out

Report •

#5
January 14, 2011 at 23:21:01
[1] Avoid using reserved words, like command, for vars or labels.

[2] You can save a ton of clutter by CALLing the chosen sub.

:: ===================================================
@echo off & setLocal enableDELAYedeXpansion

set /p C=pick hey or bye :
call :!C!
goto :eof

:hey
echo here's hey
goto :eof

:bye
echo bye bye
goto :eof


=====================================
Life is too important to be taken seriously.

M2


Report •

Ask Question