Issue with batch file encoding

自古美人都是妖i 提交于 2019-12-04 16:56:43

Ipconfig output is ANSI, wmic is unicode

If you output wmic before ipconfig, when readed it is considered unicode, as the start or the file is it. And output of ipconfig is garbage as there is no double byte characters.

If ipconfig is used before wmic, file is considered ansi and output of wmic is space separated

Use find to filter and reencode to ansi

wmic bios get serialnumber | find /v "" >> "C:\%computername%-info.txt"

So all command output is ansi

WMIC output encoding is Unicode, I don't know if Ipconfig uses the same encoding.

Try to set the output encoding of CMD to ANSI:

CMD /A /C "Your command here"

Cmd /? Help:

/A Output ANSI characters


Then try this:

CMD /A /C "ipconfig /all > "C:\%computername%-info.txt""
CMD /A /C "wmic bios get serialnumber >> "C:\%computername%-info.txt""

try

wmic /append:"%computername%-info.txt" bios get serialnumber 

or for nicer output:

wmic /append:"%computername%-info.txt" bios get serialnumber /value

no garbage (but some empty lines, which the solution from MC_ND doesn't have) Nevertheless, you may add the /value to his solution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!