是否可以将环境变量设置为cmd.exe中的命令的输出 [英] Is it possible to set an environment variable to the output of a command in cmd.exe

查看:138
本文介绍了是否可以将环境变量设置为cmd.exe中的命令的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做相当于

set ENVAR=`some-command`

在Windows / cmd.exe脚本中。 Cygwin不是一个选项。

In a windows/cmd.exe script. Cygwin is not an option.

对于奖励标记:有一些cmd.exe等同于一般的反引号?

For bonus marks: Is there some cmd.exe equivalent of backticks in general?

推荐答案

一个快速和脏的方式将重定向到一个文件,然后阅读这个,例如

A quick and dirty way would be redirecting it to a file and then reading this, e.g.

some-command>out.txt
set /p ENVAR=<out.txt


$ b b

我认为也可以帮助你,但我不记得确切的语法。尝试类似

I think for can also help you, but I don't remember the exact syntax. Try something like

for /f "usebackq" %x in (`some-command`) do set ENVAR=%x

我可能忘记了一些令牌 $ c> delim 在选项...

I probably forgot some token or delim in the options...

这篇关于是否可以将环境变量设置为cmd.exe中的命令的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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