WMIC enconding issue when run command from Linux

时间:2018-02-15 12:32:05

标签: character-encoding windows-10 interop wmic wql

I'm trying to get informations from a windows machine using WMIC in Linux.

Basically, my commands looks like below:

wmic '--authentication-file=/tmp/auth_file' '//127.0.0.1' 'SELECT Name FROM Win32_ComputerSystem'

The connection works fine and the results are correctly printed in the console. The problem is when the info has some type of encoding (like UserNames, for example). In these cases, I always get strange results.

With a quick search, I found some similar issues here and the problem is the encoding of wmic output (that is UNICODE).

As suggested, I tried pipe the output to more, but it causes no effect.

My question is: Are there anyway to force the wmic output to ASCII or ISO-8859-1 when using it through Linux? Apparently, this is the only way to get the right character-enconding.

UPDATE

Just to add more infos.

The wmic command refers to a linux client that uses WMI in a remote connection.

Since this command will be called through scripts (shell, php and python), I tried to make a encoding conversion inside a simple PHP code, but apparently, it does not work, 'cause the detected encode for the output is ISO-8859-1, and conversions for ASCII or UTF-8 simple doesn't work. below is a minimalist version of PHP script

//$cdm is a command like the example above
exec("$cmd", $out);
//also tried to parse $out and used just the string with the encoding problems in the functions below 
var_dump(mb_detect_encoding($out, "CP850, UTF-8, ISO-8859-1, ASCII")); // it returns "ISO-8859-1"
var_dump(mb_convert_encoding($out, "ASCII", 'ISO-8859-1'));
var_dump(mb_convert_encoding($out, "UTF-8", 'ISO-8859-1'));
var_dump(mb_convert_encoding($out, "ISO-8859-1", 'UTF-8'));

Info:

  • Linux: Debian 8
  • Windows: Windows 10

0 个答案:

没有答案