First off, your logic does not require an ELSE:
:CommandCheck
If exist "someFile" goto start
echo !!Java not installed!! Installing supported version now
goto install
But I don't think you are attempting to check for the existence of a file. Instead you are attempting to run the command java -version, and you want to goto start if that command was successful, and print a message and goto install if it failed.
You can use the && operator to conditionally execute a command if the prior command succeeded. There is a coralary || to execute a command if the prior command failed.
someCommand && echo someCommand succeeded || echo someCommand failed
You only need one or the other. I also assume you do not need to see the ouput (or error message) of the java -version test.
:CommandCheck
java -version >nul 2>nul && goto start
echo !!Java not installed!! Installing supported version now
goto install
If you should ever want to truly use IF ELSE with parentheses, there are a couple important syntax rules
- The parentheses must be on the same lines as the preceding IF and ELSE
- There must be a space before each opening parenthesis
Here is an example
if exist "someFile" (
echo someFile exists
) else (
echo someFile does NOT exist
)
It can all be put on one line
if exist "someFile" (echo someFile exists)else (echo someFile does NOT exist)
The following fails because the opening parentheses are not preceded by a space, so "someFIle"( and else( are treated as tokens, which cannot work.
if exist "someFile"(echo someFile exists)else(echo someFile does NOT exist)
The following fails because the parentheses must be on the same lines as IF and ELSE
if exist "someFile"
(echo someFile exists)
else
(echo someFile does NOT exist)