Set variable from exe output using batch file

I want to check Edge webdriver version using batch file. The name of the webdriver is msedgedriver.exe and I can check the version using this command manually.

msedgedriver.exe -v

And the output is

MSEdgeDriver 96.0.1054.62 (f97cb2ce0103f6eaa6dc1994d77748c659744916)

But when I use batch for to get the output, it shows nothing. The batch code:

FOR /F "tokens=* USEBACKQ" %%F IN ('msedgedriver.exe -v') DO (
SET var=%%F
)
ECHO %var%

I've tried every answer in How to set commands output as a variable in a batch file link. I've checked the file path and it's correct. and tried 'call "msedgedriver.exe -v"' or 'msedgedriver.exe /v' or every other combination.


Solution 1:

I suspect that because the output has parentesis "()" you would have to use some extra quotes:

@echo off
FOR /F "tokens=2" %%F IN ('"msedgedriver.exe -v"') DO SET var=%%F

echo %var%
pause