在批处理文件中将ECHO/TYPE输出设置为变量 [英] Set ECHO / TYPE output as a Variable in Batch Files

查看:38
本文介绍了在批处理文件中将ECHO/TYPE输出设置为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在批处理文件中将TYPE或ECHO的输出设置为变量?

Is it possible to set the output 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"

对于 echo ,您不需要做任何特别的事情,只需更改

For echo you don't need to do anything special, just change

echo Foo

进入

set Var=Foo

对于文件,也可以选择其中一个

And for files there is also the option of either

set /p Var=<file.txt

for /f "delims=" %%x in (file.txt) do set "Var=%%x"

这篇关于在批处理文件中将ECHO/TYPE输出设置为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆