in reply to Re^2: unpacking wmic command's unicode output
in thread unpacking wmic command's unicode output

This appears to work:

wmic.exe process | perl -CS script.pl

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^4: unpacking wmic command's unicode output
by ikegami (Patriarch) on Nov 12, 2008 at 18:02 UTC
    I don't get the -CS. Does wmic really output UTF-8? Wouldn't it be more appropriate to use wmic process | perl script.pl?
      Does wmic really output UTF-8?

      It appears it does (some form of unicode anyway), if you redirect its output to a file (or via a pipe):

      c:\test>wmic.exe process > junk c:\test>u:head -c 200 junk  ■C a p t i o n C o m m a n d L i n +e

      That first spludge(*) is the LE BOM 0xfffe. (It was a spludge when I c&p'd it!)

      Probably utf-16le I think, but whatever it is, using -CS does seem to cause perl to work out what it is getting and treat it appropriately:

      c:\test>wmic.exe process | perl -CS -pe1 > junk c:\test>u:head -c 200 junk Caption CommandLine

      Whether by accident or design, it is useful.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        I didn't suggest
        wmic.exe process > junk
        I suggested you drop the -CS, so you need to compare
        wmic.exe process | perl -CS -pe1 > junk
        to
        wmic.exe process | perl -pe1 > junk

        It's simple,

        • If wmic outputs "C a p t i o n", then it's cleary using a 16-bit encoding and -CS is guaranteed to hurt.
        • If wmic doesn't output "C a p t i o n", then you've lost your justification for using -CS.
Re^4: unpacking wmic command's unicode output
by goibhniu (Hermit) on Nov 11, 2008 at 20:06 UTC

    So it DOES! Thank you, thank you, O sage. I'd have been weeks in perlpacktut were it not for this elegant solution!


    #my sig used to say 'I humbly seek wisdom. '. Now it says:
    use strict;
    use warnings;
    I humbly seek wisdom.