3

I am currently creating a segment of a larger batch file that needs to let the user interact with the command prompt, but I seem to be having issues with the IF Statements.

The following code is what I've been trying:

:ONE2
cls
echo Free Roam is used like command prompt, but with additional commands.
echo Type FRHELP for a list of additional commands.

:COMMANDLOOP
echo.
set /P TEMPCMD=%CD% : 

IF %TEMPCMD% == QUIT (
GOTO END2

) else if %TEMPCMD% == FRHELP (
GOTO COMMANDSLIST

) else (
%TEMPCMD%
GOTO COMMANDLOOP
)

:COMMANDSLIST
echo.
echo FRHELP = Display Free Roam Commands
echo QUIT   = Leave your current Free Roam Session
GOTO COMMANDLOOP

What happens is, I can make multi-part commands (EG: cd ..) without the IF statements. But with the IF statements, it will only allow me to make single part commands (EG: dir).

If I have the IF statements as listed above, it will give me the "'..' was unexpected" error and exit.

Is there any way to pass my TEMPCMD variable to the command prompt with these IF statements and not get this error?

  • I believe I solved my own issue, it appears to work if I put quotation marks on my variables in the IF statement: IF "%TEMPCMD%" == "QUIT" ( GOTO END2 ) – Captain PlanIT Jun 14 '13 at 16:02

1 Answers1

3

try this, it works for me without any error:

@echo off &setlocal

:COMMANDLOOP
echo.
set "TEMPCMD=%CD%"
set /P "TEMPCMD=%CD% :" 

IF "%TEMPCMD%"=="QUIT" (GOTO END2
) else (
    if "%TEMPCMD%"=="FRHELP" (
        GOTO COMMANDSLIST
    ) else (
        GOTO COMMANDLOOP
    )
)

pause
:COMMANDSLIST
echo.
echo FRHELP = Display Free Roam Commands
echo QUIT   = Leave your current Free Roam Session
GOTO COMMANDLOOP
Endoro
  • 37,015
  • 8
  • 50
  • 63