sabisabi sabisabi - 6 months ago 22
Bash Question

cmd is somehow writing chinese text as output

I have some trouble with cmd.exe , I use it sometimes to create files and write there the output. But if i try this:

wmic logicaldisk get name, freespace >> output.txt
echo %date% >> output.txt


And I start it 2-3 times, I get an output.txt like:

FreeSpace Name
17990881280 C:
D:
㠱〮⸴〲㈱ഠ䘊爀攀攀匀瀀愀挀攀    一愀洀攀  ഀ਀㄀㜀㤀㤀 㠀㠀㄀㈀㠀   䌀㨀    ഀ਀             䐀㨀    ഀ਀㄀⸸㐰㈮㄰′਍


Well this chinese text there looks funny, but I would like to see the date. I think somehow the encoding is changed with date. Because if I do echo %date% >> output.txt alone everything is fine, I get the date. What should I do, I would like to get the wmic output and the date. Any ideas? Thank you

Answer Source

WMIC has some weird output. I've seen a discussion where it was said WMIC uses unicode, but I think the situation is more complicated than that. If I capture WMIC output to a file and use a hex editor, I see an extra carriage return at the end of each line. I am completely at a loss as to how the date content is converted into gibberish when the output.txt is typed. (codepage issue? but how?) On my machine I get question marks where the date should be.

I was able to fix the problem by using

wmic logicaldisk get name, freespace | more >>output.txt
echo %date%>>output.txt