我的批处理文件中有这个脚本——
if not exist "%JAVA_HOME%" (
echo JAVA_HOME '%JAVA_HOME%' path doesn't exist) --- (1)
else (
echo Setting JAVA property to '%JAVA_HOME%\bin\java' --- (2)
set "JAVA=%JAVA_HOME%\bin\java")
%JAVA_HOME%
被设置为C:\Program Files (x86)\Java\jdk1.7.0_45
。这个位置存在于我的机器上,但上面的代码执行第 (1) 行,为什么?
跟进:
快把我逼疯了,我现在有这个剧本——
if "x%JAVA_HOME%" == "x" (
set JAVA=java
echo JAVA_HOME is not set. Unexpected results may occur.
echo Set JAVA_HOME to the directory of your local JDK to avoid this message.
) else (
if not exist "%JAVA_HOME%" (
echo Here ----------------------------------> note this line !!
echo JAVA_HOME '%JAVA_HOME%' path doesn't exist
goto END
) else (
echo Setting JAVA property to '%JAVA_HOME%\bin\java'
set "JAVA=%JAVA_HOME%\bin\java"
)
)
:END
the%JAVA_HOME%
设置正确(它是C:\Program Files (x86)\Java\jdk1.7.0_45
)。但是当我运行时,我得到了这个错误——
prompt> test.bat
prompt> \Java\jdk1.7.0_45' was unexpected at this time
prompt> echo JAVA_HOME 'C:\Program Files (x86)\Java\jdk1.7.0_45' path does not exist
到底是怎么回事?另请注意,该行echo Here
也不会执行。