Skip to content

Add options to exec #40

@liudonghua123

Description

@liudonghua123

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions