Captain PlanIT
Captain PlanIT

Reputation: 33

Batch - User Input to Command Prompt (IF statement issue)

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?

Upvotes: 3

Views: 8867

Answers (1)

Endoro
Endoro

Reputation: 37589

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

Upvotes: 3

Related Questions