我正在使用以下内容输出从另一个站点获取的 java 版本:
java -version 2> java.txt
for /f "tokens=3" %%x in ('find /i "java version" java.txt')
输出是:
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
这是完整的代码:
@echo off
set JavaTemp=C:\Windows\Gpologs
java -version
if "%ErrorLevel%"=="0" ( goto VersionCheck ) ELSE ( goto Install )
:VersionCheck
java -version 2> %JavaTemp%\java.txt
for /f "tokens=3" %%x in ('find /i "java version" %JavaTemp%\java.txt') do (
if %%~x==1.7.0_45 goto :eof
if %%~x==1.7.0_40 goto Install
if %%~x==1.7.0_25 goto Install
if %%~x==1.7.0_21 goto Install
if %%~x==1.7.0_17 goto Install
if %%~x==1.7.0_15 goto Install
)
:Install
msiexec /i "\\servershare\sharename\Java\jre1.7.0_45_x86\jre1.7.0_45.msi" /qn
if %ErrorLevel% EQU 0 (
>>"\\servershare\sharename\jre_1.7.45.x64.csv" echo "%computername%","%date%","%Time%","%ErrorLevel%","Java Runtime 1.7.0_45x86 Installed"
>>"%windir%\GpoLogs\jre_1.7.45.x64.txt" echo "Java Runtime 1.7.0_45x86 Installed"
) else (
>>"\\servershare\sharename\JavaInstallErrors.csv" echo "%computername%","%date%","%Time%","%ErrorLevel%","Error trying to install Java 1.7_45x86"
)
我只需要知道为什么令牌是 3?请尽快解释一下,这会更有意义:)