如何将批处理(CALL)命令的输出存储到变量 [英] How to store the output of batch (CALL) command to a variable
本文介绍了如何将批处理(CALL)命令的输出存储到变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有批处理文件,它有命令调用 second.bat
文件。当它调用时它将产生单行输出。我想将该行存储为变量。
CALL second.bat
pre>
我尝试使用以下命令行,但没有使用
FOR / Ftokens = * USEBACKQ%% F IN('COMMAND')do SET result = %% F
FOR / Ftokens = 1 delims =%% A IN DO SET NumDocs = %% A
我不知道要用
COMMAND
解决方案正如帮助将告诉你,
code>应该是你要运行的命令,并获得输出。所以在你的情况下
second.bat
。至少它适用于我:@echo off
FOR / Ftokens = *%% F IN ('second.cmd')do SET result = %% F
echo%result%
注意,如果您使用
'
分隔命令,则不能使用usebackq
选项。I have the batch file which has the command to call
second.bat
file. It will produce single line of output when it called. I want to store that line into variable.CALL second.bat
I have tried using the following lines of commands but no use
FOR /F "tokens=* USEBACKQ" %%F IN ('COMMAND') do SET result=%%F FOR /F "tokens=1 delims= " %%A IN ('COMMAND') DO SET NumDocs=%%A
I don't know what to replace with
COMMAND
解决方案As the help will tell you,
COMMAND
should be the command you want to run and get the output of. So in your casesecond.bat
. At least it works for me:@echo off FOR /F "tokens=*" %%F IN ('second.cmd') do SET result=%%F echo %result%
Note that you cannot use the
usebackq
option if you're using'
to delimit your command.这篇关于如何将批处理(CALL)命令的输出存储到变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文