So here two example codes and what they return.
Code:
@echo off
hostname >> "C:test.txt"
wmic cpu get name >> "C:test.txt"
for /f "tokens=2 delims=:" %%i in ('ipconfig ^| findstr "IPv4" ^| findstr [0-9]') do echo %%i >> "C:test.txt"
Output:
Station1
N a m e
I n t e l ( R ) C o r e ( T M ) i 5 – 3 5 7 0 C P U @ 3 . 4 0 G H z
192.168.1.109
Notice how there is a space added between each letter when the value for the CPU name is returned? This also applies if I try other wmic commands such as wmic memphysical get MaxCapacity
.
Alternatively, if I rearrange the code like so:
@echo off
wmic cpu get name >> "C:test.txt"
hostname >> "C:test.txt"
for /f "tokens=2 delims=:" %%i in ('ipconfig ^| findstr "IPv4" ^| findstr [0-9]') do echo %%i >> "C:test.txt"
The output is correctly spaces but now is missing the non-wmic commands and comes up with with random chinese like so:
Name
Intel(R) Core(TM) i5-3570 CPU @ 3.40GHz
敔档瑳瑡潩㍮ㄠ㈹ㄮ㠶ㄮㄮ㤰ഠ
What am I missing here that is causing the outputs to appear like this?
I would be fine with the code from example one but it would be additional work with output that has a bunch of spaces between the letters.