Reputation: 172
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 /allWindows 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! :)
Upvotes: 3
Views: 926
Reputation: 18827
I liked the @Magoo's answer ! and i just create a batch file in order to show you the difference of using with and without More
command the behivor of exporting results in a text file.
@echo off
REM https://stackoverflow.com/questions/34075745/wmic-bat-file-will-not-export-output-properly?answertab=active#tab-top
Title WMIC.bat file will not export/output properly
set "WithoutMore=%~dp0WithoutMore.txt"
set "WithMore=%~dp0WithMore.txt"
(
wmic csproduct
wmic cpu get name,AddressWidth,Description
wmic diskdrive get model,size
WMIC PATH Win32_Battery Get EstimatedChargeRemaining
ipconfig /all
)>"%WithoutMore%"
Start "" "%WithoutMore%"
(
wmic csproduct
wmic cpu get name,AddressWidth,Description
wmic diskdrive get model,size
WMIC PATH Win32_Battery Get EstimatedChargeRemaining
ipconfig /all
) | more>"%WithMore%"
Start "" "%WithMore%"
Upvotes: 0
Reputation: 79983
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
Upvotes: 5