4

When I run the command

wmic memorychip get capacity

from the command line in the cmd window, the output on the screen looks like:

Capacity    
2147483648 

However, if I add this command to a batch file and try to redirect the output to a file, like:

wmic memorychip get capacity >> %LOG%

(where %LOG% is just my log file where I want to append the data), it gets saved in the log file as:

C a p a c i t y         

 2 1 4 7 4 8 3 6 4 8     

Here spaces got inserted before each character. In the Notepad++ it shows NULs inserted, for some reason I am not able to paste it here :(

Does anybody know why the output is changed such a way and how to avoid this transformation?

shx2
  • 61,779
  • 13
  • 130
  • 153
user2296601
  • 41
  • 1
  • 2

3 Answers3

3

Unicode for sure.

Try

wmic memorychip get capacity |more>> %LOG%
Magoo
  • 77,302
  • 8
  • 62
  • 84
  • it may look nicer in your logfile, if you use `wmic memorychip get capacity /value` which gives you `Capacity=2147483648` – Stephan Apr 19 '13 at 09:16
  • Disagree, the `/value` did not work for the command I was using but using `|more` worked great. – Chef Pharaoh Apr 15 '16 at 14:46
1

In case you have the output file but cannot run the original command again, cat original.txt | tr -d "\00" > cleaned.txt will produce a new file with null characters removed. This command assumes common Unix shell tools are available, such as those provided by BusyBox .

Daniel O
  • 336
  • 2
  • 3
  • 8
0

the problem is that wmic works in unicode but the cmd in ascii.Try this:

for /f "delims=" %a in ('wmic memorychip get capacity') do @for /f "delims=" %b in ("%a") do echo %b > log
npocmaka
  • 55,367
  • 18
  • 148
  • 187