Windows批处理文件:如何设置一个命令的结果变量? [英] Windows batch files: How to set a variable with the result of a command?
本文介绍了Windows批处理文件:如何设置一个命令的结果变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在一个bash的环境我通常做:
Under a bash environment I usually do:
var=$(command -args)
和我使用 $ VAR
,其值设置好的作为命令的结果。
同样进入到更常规
and the I use $var
with its value setted as the result of the command.
The same goes to a more conventional
set var=`command -args`
在几乎所有的UNIX外壳兼容。
compatible in almost every unix shell.
我怎么可以定义在这样的窗口bat文件的变量?
我试过
How could I define a variable in a windows bat file like that? I've tried
set var=command -args
但我只拿到命令-args字符串。
but I only get the "command -args" string.
推荐答案
要做到你需要写什么杰西从一个批处理文件描述
To do what Jesse describes from a batch file you will need to write
for /f "delims=" %%a in ('ver') do @set foobar=%%a
不过,我会建议使用您的Windows系统上的Cygwin 如果你使用UNIX脚本类型
But, i will suggest using Cygwin on your Windows system if you are used to unix type scripting.
这篇关于Windows批处理文件:如何设置一个命令的结果变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文