從一個批處理文件進行解析的格式version=value
的:
@For /F "UseBackQ Skip=1 Delims=" %%A In (`WMIC DataFile Where "Name='C:\\Program Files (x86)\\App\\name.exe'" Get Version`) Do @For /F "Tokens=*" %%B In ("%%~A") Do @Set "pver=%%B"
或者在較短的線:
@Echo Off
For /F "UseBackQ Skip=1 Delims=" %%A In (`WMIC DataFile Where^
"Name='C:\\Program Files (x86)\\App\\name.exe'" Get Version
`) Do For /F "Tokens=*" %%B In ("%%~A") Do Set "pver=%%B"
從命令line:
For /F "UseBackQ Skip=1 Delims=" %A In (`WMIC DataFile Where "Name='C:\\Program Files (x86)\\App\\name.exe'" Get Version`) Do @For /F "Tokens=*" %B In ("%~A") Do @Set "pver=%B"
在這兩種情況下,請注意WMIC將traili用固定寬度的空間填充輸出。之後你可能需要處理它們。
像這樣也許:
@Echo Off
For /F "UseBackQ Skip=1 Delims=" %%A In (`WMIC DataFile Where^
"Name='C:\\Program Files (x86)\\App\\name.exe'" Get Version
`) Do For /F "Tokens=*" %%B In ("%%~A") Do Call :Sub %%B
Echo %pver%
Pause
Exit/B
:Sub
Set "pver=%*"
你聲稱使用批處理file'代碼',但是你用命令行的語法。在批處理文件中將每個「%a」更改爲「%% a」。 – Stephan
我會試着讓'wmic'命令行工作在'/ F'周圍前......' – aschipfl