Node.js 我正在尝试在节点中重复shelljs exec类型的执行

Node.js 我正在尝试在节点中重复shelljs exec类型的执行,node.js,exec,shelljs,Node.js,Exec,Shelljs,我以前使用过shelljs,在这里我调用了如下命令: require('shelljs/global'); let res = exec('echo hello').stdout 但我希望在节点中实现这一点,而不依赖shelljs。 问题是我已经找到了node的例子,其中有很多我遇到了麻烦。 感谢您的帮助非常简单的答案是使用的版本。命令运行时,stdout不会出现,结果也不会有shelljs提供的好属性,只有stdout数据 const { execSync } = require('chi

我以前使用过shelljs,在这里我调用了如下命令:

require('shelljs/global');

let res = exec('echo hello').stdout
但我希望在节点中实现这一点,而不依赖shelljs。 问题是我已经找到了node的例子,其中有很多我遇到了麻烦。
感谢您的帮助

非常简单的答案是使用的版本。命令运行时,stdout不会出现,结果也不会有shelljs提供的好属性,只有
stdout
数据

const { execSync } = require('child_process')
const exec = (cmd) => execSync(cmd).toString()
const res = exec('echo "hello there"')
完整的shelljs实现在中,它通过脚本运行命令,为同步执行启用实时输出+捕获变量。解决方案的复杂程度取决于您需要的功能