我没有批处理脚本的强大背景,如果有明显的答案,请道歉。
我试图将命令提示符的输出定向到变量。我可以将它输出到像这样的文件
go test -race > output.txt
在这种情况下,output.txt将填充go test -race的输出。我想要做的是将它输出到一个变量,类似于
set iamavariable=nothotdog
go test -race > %iamavariable%
echo %location%
这会创建一个名为nothotdog的文件,其输出为go test -race,并回显nothotdog,而不是回显go test -race的输出
答案 0 :(得分:1)
要正确获取命令的结果,您需要for
循环。
for /f %%p in ('your command') do set result=%%p
echo %result%
如果命令输出多个单词/数字/字符/数字,那么这可能会更好:
For /F "Delims=" %%A In ('go test -race') Do Set "result=%%A"
Echo %result%