I'm trying to fetch my java jdk path using a batch script. Here is what i have so far:
@echo off
for /f %%j in ("java.exe") do (
set JAVA_HOME=%%~dp$PATH:j
)
if "%JAVA_HOME%".==. (
@echo Java.exe not found
@echo Please make sure that java JDK 1.7 or 1.8 is installed
)
In the if statement, since the path is in C:\Program Files\Common Files\etc.., i receive the error Common was not expected at this time. However, the IF condition does not work properly if Java is not found.
If i remove the "" surrounding JAVA_HOME, i get an error that Files was not expected at this time. In this case the IF condition works properly if JAVA.exe is found.
Why is it allowing the space or the '\' in \Program Files and stopping afterwards?
if "%JAVA_HOME%"=="" (
?