Dos Assign Command Output To Variable (when Output Is Of

[Solved] Dos Assign Command Output To Variable (when Output Is Of | Basic - Code Explorer | yomemimo.com
Question : dos assign command output to variable (when output is a single line)

Answered by : plamen-grozdanov

FOR /F "tokens=* USEBACKQ" %%F IN (`command`) DO (
SET var=%%F
)
ECHO %var%

Source : https://stackoverflow.com/questions/6359820/how-to-set-commands-output-as-a-variable-in-a-batch-file | Last Update : Wed, 24 Nov 21

Question : dos assign command output to variable (when output is of multiple lines)

Answered by : plamen-grozdanov

SETLOCAL ENABLEDELAYEDEXPANSION
SET count=1
FOR /F "tokens=* USEBACKQ" %%F IN (`command`) DO ( SET var!count!=%%F SET /a count=!count!+1
)
ECHO %var1%
ECHO %var2%
ECHO %var3%
ENDLOCAL

Source : https://stackoverflow.com/questions/6359820/how-to-set-commands-output-as-a-variable-in-a-batch-file | Last Update : Wed, 24 Nov 21

Answers related to dos assign command output to variable (when output is of multiple lines)

Code Explorer Popular Question For Basic