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?

1
  • 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 ) Commented Jun 14, 2013 at 16:02

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

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.