问题
I have the following command:
c:\wmic baseboard get Manufacturer
Manufacturer
ASUSTeK Computer INC.
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.
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)
回答1:
Try this:
@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
来源:https://stackoverflow.com/questions/47884082/parse-wmic-output-to-set-returned-value-as-a-variable-windows-batch