Reputation: 1634
I'm creating a batch file to setup up environmental variable's for JSHOP2. The code accepts two user inputs and compares them with an existing ClassPath variable, if it does not exists then it sets the environmental variables. Here is my code:
@echo off
color 0a
echo ............................Welcome to path to shop............................
echo .... Make sure you provide exact paths with full file name when prompted.
echo .... Once given the path of the file make sure you don't change the location of the file in your computer.
set /p "antlrPath=Enter the path of the antlr.jar file in your computer: "
set /p "jshop2Path=Enter the path of the compiled JSHOP2 source file (SomeName.jar) in your computer: "
set @specifiedPath= %antlrPath%;%jshop2Path%
echo %@specifiedPath% %CLASSPATH% ::code runs fine upto this line then cmd exits unexpectedly
if %@specifiedPath% == %CLASSPATH%
goto isAlreadySet
goto isNotAlreadySet
:isAlreadySet
echo yesss!
:isNotAlreadySet
echo no
pause
What is the problem?
Edit: code updated as asked by aphoria.
@echo off
color 0a
echo ............................Welcome to path to shop............................
echo .... Make sure you provide exact paths with full file name when prompted.
echo .... Once given the path of the file make sure you don't change the location of the file in your computer.
set /p "antlrPath=Enter the path of the antlr.jar file in your computer: "
set /p "jshop2Path=Enter the path of the compiled JSHOP2 source file (SomeName.jar) in your computer: "
set @specifiedPath= %antlrPath%;%jshop2Path%
echo %@specifiedPath% %CLASSPATH%
if "%@specifiedPath%" == "%CLASSPATH%" (
goto isAlreadySet
) ELSE (
goto isNotAlreadySet
)
:isAlreadySet
echo yesss!
:isNotAlreadySet
echo no
pause
Upvotes: 1
Views: 88
Reputation: 1634
Thank you guys for your support. My problem is finally solved. For all those who get this problem here is my final code.
@echo off
color 0a
echo ............................Welcome to path to shop............................
echo .... Make sure you provide exact paths with full file name when prompted.
echo .... Once given the path of the file make sure you don't change the location of the file in your computer.
set /p "antlrPath=Enter the path of the antlr.jar file in your computer: "
set /p "jshop2Path=Enter the path of the compiled JSHOP2 source file (SomeName.jar) in your computer: "
set @specifiedPath=%antlrPath%;%jshop2Path%
echo %@specifiedPath% %CLASSPATH%
if "%@specifiedPath%" == "%CLASSPATH%" (
goto isAlreadySet
) ELSE (
goto isNotAlreadySet
)
:isAlreadySet
echo yesss!
goto end
:isNotAlreadySet
echo no
:end
pause
Thanks Again :)
Upvotes: 1
Reputation: 20179
The IF
statement must all be on the same line or use parentheses across multiple lines.
UPDATE
/I
option to the IF
statement for case insensitivity.You could do this:
if /I "%@specifiedPath%" == "%CLASSPATH%" goto isAlreadySet
goto isNotAlreadySet
Or this:
if /I "%@specifiedPath%" == "%CLASSPATH%" (
goto isAlreadySet
) ELSE (
goto isNotAlreadySet
)
Upvotes: 0