WMIC.bat file will not export/output properly

2020-04-27 09:05发布


I am attempting to run a batch file in CMD that includes the following,

wmic csproduct
wmic cpu get name
wmic diskdrive get model,size
ipconfig /all

When I copy and paste this into CMD, I am able to watch the commands run. I am successfully able to copy and paste all of the data into a text document without issue.

The Issue: When I attempt to export/output this exact file into a .txt or .rtf,

C:> 1.bat > 1.txt

"ipconfig" pulls properly, yet the WMIC commands do not does not give me any issues and outputs to the file correctly. However, whether I export/output this batch as a .txt or .rtf,

the WMIC commands are leaving spaces or NUL in between each character in the output file.

I will open the file that reads

C:\Windows\system32>wmic csproduct C a p t i o n D e s c r i p t i o n I d e n t i f y i n g N u m b e r N a m e S K U N u m b e r U U I D V e n d o r V e r s i o n
C o m p u t e r S y s t e m P r o d u c t C o m p u t e r S y s t e m P r o d u c t T o b e f i l l e d b y O . E . M . T o b e f i l l e d b y O . E . M . C D 4 A E B A 0 - B 7 4 F - 1 2 D C - 8 F B A - 6 0 A 4 4 D 6 3 9 A B E T o b e f i l l e d b y O . E . M . T o b e f i l l e d b y O . E . M .
C:\Windows\system32>ipconfig /all

Windows IP Configuration

Host Name . . . . . . . . . . . . : octocore
Primary Dns Suffix . . . . . . . :
...etc...etc

Is there a way to export/output this "combo batch" so that it pulls correctly?

P.S. I attempted to read [https://superuser.com/questions/812438/combine-batch-wmic-ansi-unicode-output-formatting][1] , but my question actually contains the wmic and native commands from one batch file.

[1]: https://superuser.com/questions/812438/combine-batch-wmic-ansi-unicode-output-formatting

P.P.S. This is my first post in StackOverflow, so thank you in advance! :)

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2020-04-27 10:01

WMIC output is in unicode. Pipe each wmic output to more.

> creates a new file.>> creates a new file if one does not already exist and appends to that file if it exists.

So, the cure would appear to be

wmic csproduct | more
wmic cpu get name | more
wmic diskdrive get model,size | more
ipconfig /all
查看更多
登录 后发表回答