解析WMIC输出以将返回值设置为变量(Windows批处理) [英] Parse WMIC output to set returned value as a variable (windows batch)
问题描述
我有以下命令:
c:\wmic baseboard get Manufacturer
Manufacturer
ASUSTeK Computer INC.
我想将其输出保存到变量中,并像在bash上一样进行处理: esxi_hwinfo.sh @ GitHub 例如:删除一些子字符串,缩短数字,将一个字符串转换为另一个,等等.
I'd like to save it's output into variable and process some way like I did it with bash here: esxi_hwinfo.sh @ GitHub e.g.: remove some sub-strings, shorten numbers, convert one string to another etc.
是否可以遍历变量内部的行并获得例如第二行?我看过的示例仅适用于文件(/f"delims =" %% 1 in('type!foo!')中的可以
).如果我使用变量而不是文件,则表明没有此类文件.
Is it possible to iterate over lines inside variable and get for instance the second one? Examples which I've seen work only with files (for /f "delims=" %%1 in ('type !foo!') do
). If I use variable instead of file it says that there is no such file.
我不想使用文件作为中介,因为我认为这通常是个坏主意.
I don't want to use files as intermediaries since I think it's generally a bad idea.
没有我要工作的问题代码.关于我要实现的技术实施(或可能性)存在疑问.它更像是怎么做"而不是怎么了"问题(例如此处)
There is no problem code which I want to work. There is a question about technical implementation (or possibility) of what I'm trying to achieve. It's more like "how to" than "what's wrong" question (like the most in here)
推荐答案
尝试一下:
@echo off
set "manu="&for /f "skip=1 tokens=*" %%m in ('wmic baseboard get manufacturer') do if not defined manu set "manu=%%m"
rem now do things to %manu%
echo %manu%
pause
这篇关于解析WMIC输出以将返回值设置为变量(Windows批处理)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!