for /f "usebackq tokens=*" %%I in (`__COMMAND__ 2^>nul`) do ( set MYVAR=%%I )
in this case, the redirection and conditional execution statements must be escaped with a caret.
Or put everything in double quotes:
for /f "usebackq tokens=*" %%I in (`"__COMMAND__ 2>nul"`) do ( set MYVAR=%%I )
Using delayed extension is also possible:
@echo off setlocal enableDelayedExpansion set "command=__COMMAND__ 2>nul" for /f "usebackq tokens=*" %%I in (`!command!`) do ( set MYVAR=%%I )
source share