On 11.04.2023 09:15, Leonid Mironov via Cygwin wrote:
I am trying to feed the output of wmic.exe - a windows console program, to
cygwin bash script.
wmic.exe produces UTF16LE output with BOM and CR/LFs, so I am using dos2unix to
convert it.
The problem is that when I write wmic.exe output to a file and then use
dos2unix to convert this file
I get the expected result - ASCII file with LFs, I get the same result when I
pipe this file to dos2unix,
but when I pipe wmic.exe output directly to dos2unix I get ASCII file with
CR/LFs and an extra empty line.
Cygwin is up to date, windows 10. What gives?
Here are the hexdumps
of 'wmic /NAMESPACE:\\\\root\\WMI PATH BatteryStatus get
charging,voltage,remainingcapacity,chargerate>file'
use "iconv" to change the codification and than d2u for the line termination
$ iconv -f UTF16 -t UTF8 file
ChargeRate Charging RemainingCapacity Voltage
0 FALSE 0 0
$ iconv -f UTF16 -t UTF8 file |od -c
0000000 C h a r g e R a t e C h a r
0000020 g i n g R e m a i n i n g C
0000040 a p a c i t y V o l t a g e
0000060 \r \n 0
0000100 F A L S E 0
0000120 0
0000140 \r \n
0000150
$ iconv -f UTF16 -t UTF8 file |d2u | od -c
0000000 C h a r g e R a t e C h a r
0000020 g i n g R e m a i n i n g C
0000040 a p a c i t y V o l t a g e
0000060 \n 0 F
0000100 A L S E 0
0000120 0
0000140 \n
0000146
--
Problem reports: https://cygwin.com/problems.html
FAQ: https://cygwin.com/faq/
Documentation: https://cygwin.com/docs.html
Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple