从命令的输出设置变量Windows批处理帮助 [英] Windows Batch help in setting a variable from command output
本文介绍了从命令的输出设置变量Windows批处理帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要运行一个简单的find命令,并将输出重定向到一个变量在Windows批处理文件。
I need to run a simple find command and redirect the output to a variable in a Windows Batch File.
我已经试过这样:
set file=ls|find ".txt"
echo %file%
不过,这是行不通的。
But it does not work.
如果我运行此命令,它的工作原理没有问题:
If I run this command it works without problems:
set file=test.txt
echo %file%
所以,很显然我的命令没有被设置为我的变量。任何人都可以帮忙吗?谢谢
So obviously my command output is not being set to my variable. Can anyone help? Thanks
推荐答案
我只是找出如何使用它管道命令,这里是我的命令(即提取一个SVN回购的头修订):
I just find out how to use commands with pipes in it, here's my command (that extracts the head revision of an svn repo) :
SET SVN_INFO_CMD=svn info http://mySvnRepo/MyProjects
FOR /f "tokens=1 delims=" %%i IN ('%SVN_INFO_CMD% ^| find "Revision"') DO echo %%i
这篇关于从命令的输出设置变量Windows批处理帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文