默认输出是Buffer对象
const {
execSync } = require('child_process')
let out = execSync("echo 'hi'")
console.log(out);
// <Buffer 68 69 0a>
需要转为字符串
const {
execSync } = require('child_process')
let out = execSync("echo 'hi'")
console.log(out.toString());
// hi
参考文章