java中的批处理,批处理文件中的Java版本

My question, is extremely similar to the following SO question: How to get Java Version from batch script?

In fact, it did almost solve my problem. The only difference is that I've to check the Java version based on %JAVA_HOME%, which the user is free to modify. The issue that I'm facing is with this code:

@ECHO OFF

SETLOCAL enableextensions enabledelayedexpansion

IF "%JAVA_HOME%"=="" (

@ECHO Please set JAVA_HOME environment variable

EXIT /B

)

@echo "%JAVA_HOME%"

REM Checking JAVA_VERSION

SET JAVA_VERSION=

FOR /f "tokens=3" %%g in ('"%JAVA_HOME%"\bin\java -version 2^>^&1 ^| findstr /i "version"') do (

SET "JAVA_VERSION=%%g"

)

%JAVA_HOME%% in my system points to "C:\Program Files\jdk1.7.0_25" (notice the space in the path)

Even with the quotes, I get the following error in command line:

'C:\Program' is not recognized as an internal or external command,

operable program or batch file.

Any idea as to how to solve this problem? (The comments to the aforementioned article also mentions this issue). I'm working on a Windows 7 machine

解决方案

FOR /f "tokens=3" %%g in ('"%JAVA_HOME%\bin\java" -version 2^>^&1 ^| findstr /i "version"') do (

SET "JAVA_VERSION=%%g"

)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值