节目的视窗批次分配输出给可变 [英] Windows batch assign output of a program to a variable
本文介绍了节目的视窗批次分配输出给可变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用MS批处理文件程序的输出分配给一个变量。
I need to assign the output of a program to a variable using a MS batch file.
因此,在GNU Bash shell中我会使用 VAR = $(应用程序为arg0 ARG1)
。我需要在Windows类似的行为使用批处理文件。
So in GNU Bash shell I would use VAR=$(application arg0 arg1)
. I need a similar behavior in Windows using a batch file.
喜欢的东西集 VAR =应用为arg0 ARG1
。
谢谢!
推荐答案
的一种方法是:
application arg0 arg1 > temp.txt
set /p VAR=<temp.txt
另外一种是:
for /f %%i in ('application arg0 arg1') do set VAR=%%i
请注意,第一个%
在 %%我
用来逃避%
,并在一个批处理文件中使用上述code时,而不是在命令行上需要了。试想一下,你的 test.bat的
有这样的:
Note that the first %
in %%i
is used to escape the %
after it and is needed when using the above code in a batch file rather than on the command line. Imagine, your test.bat
has something like:
for /f %%i in ('c:\cygwin64\bin\date.exe +"%%Y%%m%%d%%H%%M%%S"') do set datetime=%%i
echo %datetime%
这篇关于节目的视窗批次分配输出给可变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文