windows 使用批处理脚本检查环境中是否存在 JAVA_HOME
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7021873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:39:50 来源:igfitidea点击:
Check if JAVA_HOME is present in environment using batch script
提问by AabinGunz
I want to check whether JAVA_HOME is present in environment or not
So I wrote the below script a.bat
我想检查环境中是否存在 JAVA_HOME 所以我写了下面的脚本 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?
它显示“命令的语法不正确”我哪里出错了?
回答by dertkw
Try this:
尝试这个:
@echo off
IF "%JAVA_HOME%" == "" (
echo Enter path to JAVA_HOME:
set /p JAVA_HOME=
) ELSE (
echo %JAVA_HOME%
)
回答by walid2mi
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%