yoda
yoda

Reputation: 10981

Batch file get result into runtime variable

The following code is ment to get Chrome current version into a runtime variable. What am I missing here?

for /f %%i in ('wmic datafile where name="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" get Version /value') do set VAR=%%i
echo %VAR%
pause

The result :

    C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe - Invalid alias
 verb.

Upvotes: 0

Views: 139

Answers (1)

Squashman
Squashman

Reputation: 14290

Quoting gets a little different when inside a FOR command. Need the nested FOR to get rid of the empty lines.

@echo off

for /f "delims=" %%G in ('wmic datafile where "name='C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'" get Version /value ') do (
    FOR /F "tokens=2 delims==" %%H in ("%%~G") do set var=%%H
)
echo %var%
pause

Upvotes: 2

Related Questions