默认输出是Buffer对象
const { execSync } = require('child_process')
let out = execSync("echo 'hi'")
console.log(out);
// <Buffer 68 69 0a>
需要转为字符串文章来源:https://www.toymoban.com/news/detail-615753.html
const { execSync } = require('child_process')
let out = execSync("echo 'hi'")
console.log(out.toString());
// hi
参考文章文章来源地址https://www.toymoban.com/news/detail-615753.html
- https://www.runoob.com/nodejs/nodejs-process.html
- https://blog.csdn.net/weixin_43972437/article/details/130643741
到了这里,关于Node.js:execSync执行一个shell命令的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!