node-cmd
node-cmd copied to clipboard
Add options to exec
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.
I would be open to reviewing a PR to add this.
@hawyar, I will make sure I check both the promise and options in the review. Thanks for mentioning both of the issues.