13

I want to check whether JAVA_HOME is present in environment or not So I wrote the below script a.bat

if "%JAVA_HOME%" == "" 
(
echo Enter path to JAVA_HOME: 
set /p javahome=
)
if not "%JAVA_HOME%" == ""
(
echo %JAVA_HOME%
)

It shows "The syntax of the command is incorrect" where am i going wrong?

AabinGunz
  • 12,109
  • 54
  • 146
  • 218

2 Answers2

19

Try this:

@echo off
IF "%JAVA_HOME%" == "" (
    echo Enter path to JAVA_HOME: 
    set /p JAVA_HOME=
) ELSE (
    echo %JAVA_HOME%
)
dertkw
  • 7,798
  • 5
  • 37
  • 45
2
if not defined JAVA_HOME (
    :undefined
    set /p JAVA_HOME=Enter path to JAVA_HOME:
    if not defined JAVA_HOME goto:undefined
 )
echo %JAVA_HOME%
walid2mi
  • 2,704
  • 15
  • 15
  • This requires command extensions so you might want to explicitly set those first even though they are on by default. SETLOCAL ENABLEEXTENSIONS IF ERRORLEVEL 1 ECHO Unable to enable extensions – opticyclic Jan 22 '16 at 03:51