[英]Set ECHO / TYPE output as a Variable in Batch Files
Is it possible to set the output of TYPE or ECHO as a variable in a batch file?是否可以将 TYPE 或 ECHO 的 output 设置为批处理文件中的变量?
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
你不需要做任何特别的事情,只需改变
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"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.