Set ECHO / TYPE output as a Variable in Batch Files
Is it possible to set the o开发者_运维技巧utput of TYPE or ECHO as a variable in a batch file?
Convoluted, and it only works for a single line, but general:
for /f "delims=" %%x in ('some command with output') do set "Var=%%x"
For echo
you don't need to do anything special, just change
echo Foo
into
set Var=Foo
And for files there is also the option of either
set /p Var=<file.txt
or
for /f "delims=" %%x in (file.txt) do set "Var=%%x"
精彩评论