• 先将encoding设置为buffer,然后使用iconv-lite模块解码
  • 需要管理员身份运行cmd.exe
1
2
3
4
5
6
7
8
9
//先将encoding设置为buffer,然后使用iconv-lite模块解码
const iconv = require('iconv-lite');
const childProcess = require('child_process');

childProcess.exec(`ping www.baidu.com`, { encoding: 'buffer' }, (error, stdout) => {
console.log('stdout1', iconv.decode(stdout, 'cp936'));
});