Wow, it was really hard to find out what was going on here.
Firstly, I couldnโt believe what happens when the batch file is executed.
After many tests performed on Windows XP SP3 x86
wmic.exe baseboard get /format:list > Output.txt
and looked at the Output.txt file by viewing the Total Commander file manager. I saw two empty lines at the top, but that doesn't really matter. Therefore, I continued other tests.
Later, I opened Output.txt in an UltraEdit text editor and immediately saw the U-DOS status bar, indicating that the output file was encoded in small UTF-16 content with DOS line terminators. I switched to hex editing mode and could see
00000000h: FF FE 0D 00 0A 00 0D 00 0A 00 43 00 61 00 70 00 ; รฟรพ........Cap 00000010h: 74 00 69 00 6F 00 6E 00 3D 00 ; tion=.
So the output file is really a Unicode file with UTF-16 LE BOM. CR CR LF is absent. All lines complete the correct CR LF pair (carriage return + line).
Now I searched in Stack for questions with a batch file containing the words wmic Unicode and found cmd somehow writing Chinese text as a result .
The accepted dbenham answer is not very good as it creates an ANSI version of the Unicode output for wmic.exe , but the ANSI file now really contains 0D 0D 0A (= CR CR LF).
It is better to answer Dharma Leonardi , since a solution using the type command will correctly convert the Unicode output to ANSI output, until the output contains characters that are not available on the ANSI code page.
But after changing the batch code to process the ANSI-encoded wmic.exe output, the line with if defined BaseboardVersion always evaluated as true, although I could not see that this BaseboardVersion variable contained any data, and therefore the next line led to the display of the echo state.
It took me a while to learn how to insert set > Variables.txt over this condition and look at this file, that on my computer the version line is just one space. The Version value was the only value of all keys without an equal sign on the right, consisting of only one space.
Here is a batch file that finally worked on my computer and produces the expected result:
@echo off setlocal enabledelayedexpansion wmic.exe /OUTPUT:"%TEMP%\UnicodeData.tmp" baseboard get /format:list for /f "usebackq tokens=1,2* delims==" %%a in (`type "%TEMP%\UnicodeData.tmp"`) do ( if "%%a" == "Product" ( if not "%%b" == "" if not "%%b" == " " ( set "PlatformInfo=%%b" echo !PlatformInfo! echo !PlatformInfo!This overwrites the variable ) ) else if "%%a" == "Version" ( if not "%%b" == "" if not "%%b" == " " ( set "BaseboardVersion=%%b" echo !BaseboardVersion! echo !BaseboardVersion!This overwrites the variable ) ) ) del "%TEMP%\UnicodeData.tmp" endlocal