开发者

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"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜