开发者

Set ECHO / TYPE output as a Variable in Batch Files

开发者 https://www.devze.com 2023-03-10 17:26 出处:网络
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:

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

精彩评论

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