Node.js:execSync执行一个shell命令

默认输出是Buffer对象

const { execSync } = require('child_process')

let out = execSync("echo 'hi'")
console.log(out);
// 

需要转为字符串

const { execSync } = require('child_process')

let out = execSync("echo 'hi'")
console.log(out.toString());
// hi

参考文章

  1. https://www.runoob.com/nodejs/nodejs-process.html
  2. https://blog.csdn.net/weixin_43972437/article/details/130643741

你可能感兴趣的:(node.js)