const { exec } = require("child_process");
const iconv = require("iconv-lite");
const encoding = "cp936";
const bufferEncoding = "binary";
exec(`ipconfig`, { encoding: bufferEncoding }, function (err, stdout, stderr) {
if (err) {
console.log(iconv.decode(Buffer.from(err.stack, bufferEncoding), encoding));
console.log(iconv.decode(Buffer.from(err.message, bufferEncoding), encoding));
} else {
console.log(iconv.decode(Buffer.from(stdout, bufferEncoding), encoding));
console.log(iconv.decode(Buffer.from(stderr, bufferEncoding), encoding));
}
});
child_process exec 乱码
于 2022-06-29 22:56:58 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)