node-cmd icon indicating copy to clipboard operation
node-cmd copied to clipboard

Add options to exec

Open liudonghua123 opened this issue 6 years ago • 2 comments

I write my code like

cmd.get(
    'ipconfig',
    function(err,data){
        if(err) throw err;
        console.log('the output of ipconfig is : ',data)
    }
);

But the encoding of data is incorrect because the default encoding of exec is utf-8, and on some platform like a Chinese version of Windows, the output of command execution is cp936, then the final output is filled with incorrect characters.

However, I can do it with passing extra options to exec to make it work.

const iconv = require('iconv-lite');
const { exec } = require('child_process');

exec('ipconfig', { encoding: 'buffer' }, (error, stdout) => {
    console.log('the output of ipconfig is : ',iconv.decode(stdout, 'cp936'));
});

So hope to add options to the underlying exec call.

liudonghua123 avatar Sep 11 '18 09:09 liudonghua123

I would be open to reviewing a PR to add this.

RIAEvangelist avatar Jul 29 '21 00:07 RIAEvangelist

@hawyar, I will make sure I check both the promise and options in the review. Thanks for mentioning both of the issues.

RIAEvangelist avatar Jan 22 '22 17:01 RIAEvangelist