tomas / wmic

Wrapper around the Windows WMIC interface for Node.js.
12 stars 15 forks source link

Bad detection of console encoding on some Korean machines #13

Open xavier-deryckere opened 3 years ago

xavier-deryckere commented 3 years ago

Hi,

The expected output of the chcp command on Windows machines is like: Active code page: 850

In that case the following code correctly provides the actual code page: var codePage = stdout.replace(/\D/g, '');

But on some machines the output of chcp contains an error code, for instance: "활占쏙옙 占쌘듸옙 占쏙옙占쏙옙占쏙옙: 949\r\n[0x7FFAF4317EA0] ANOMALY: meaningless REX prefix used"

In such a case the codePage becomes incorrect: "9490743170" instead of the expected "949"

This ends up later with errors like Encoding not recognized: 'cp9490743170' ... (in iconv-lite actually)

May I suggest to retrieve the encoding differently, like: var codePage = stdout.replace(/\n.*$/, '').replace(/\D/g, ''); or var codePage = (/\d+/.exec(stdout)||[''])[0];

Thanks.

tomas commented 3 years ago

Would you submit a PR for this? Thanks

xavier-deryckere commented 3 years ago

Done! => https://github.com/tomas/wmic/pull/14 My first ever PR in github, hoping I did it properly :-)