批处理-将带有变量的命令输出分配给Variable [英] Batch - Assign Command output with variables to Variable

查看:83
本文介绍了批处理-将带有变量的命令输出分配给Variable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种将命令输出分配给批处理变量的方法,但是该命令在内部使用了另一个变量.

I am looking for way to assign output of a command to a batch variable, but the command internally uses another variable.

当我使用中指定的解决方案时 将命令输出分配到批处理文件中的变量

When i use the solution specified in Assign Command output to Variable in Batch file

我收到错误消息,提示此时命令内部的变量不是预期的.

I am getting error that the variable inside the command was not expected at this time.

请帮助

推荐答案

我认为这对您有用.

假设您的命令是Echo hi,并且您想要将输出('hi')存储到变量中:

Say you command was Echo hi and you wanted to store the output ('hi') into a variable:

Echo hi > out.tmp
set /p var=< out.tmp
del out.tmp

Echo %var%

其中var现在存储您的输出值.注意:它将只存储输出的第一行.如果您想做输出注释的最后一行,那么我将使用for循环代替它.

where var now stores the value of your output. Note: it will only store the first the line of output. If you want to do last line of output comment and I would make it use a for loop instead.

这篇关于批处理-将带有变量的命令输出分配给Variable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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