public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Marco Atzeri <marco.atzeri@gmail.com>
To: cygwin@cygwin.com
Subject: Re: issue when piping from a windows program
Date: Tue, 11 Apr 2023 11:02:04 +0200	[thread overview]
Message-ID: <93787f32-eb6d-92ea-e5bb-8018c35717cc@gmail.com> (raw)
In-Reply-To: <trinity-bed8517a-5458-4f9d-8ee1-6d6698fcdea7-1681197303539@3c-app-mailcom-lxa08>

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


  reply	other threads:[~2023-04-11  9:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-11  7:15 Leonid Mironov
2023-04-11  9:02 ` Marco Atzeri [this message]
2023-04-11 14:43 ` Andrey Repin
2023-04-12  7:02   ` Brian Inglis
2023-04-12  8:56 ` Takashi Yano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=93787f32-eb6d-92ea-e5bb-8018c35717cc@gmail.com \
    --to=marco.atzeri@gmail.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).