Node.js 如何在同步模式下运行节点shelljs并获取stdout和stderr
在nodejs脚本中,我有以下代码,同步进行调用并从我调用的shell脚本返回stdout:Node.js 如何在同步模式下运行节点shelljs并获取stdout和stderr,node.js,shelljs,Node.js,Shelljs,在nodejs脚本中,我有以下代码,同步进行调用并从我调用的shell脚本返回stdout: var sh = require('shelljs'); ... some code var output = sh.exec('./someshellscript.sh', {silent:true}).stdout; console.log(output); ... some more code (that shouldnt run until the script is complete) 我
var sh = require('shelljs');
... some code
var output = sh.exec('./someshellscript.sh', {silent:true}).stdout;
console.log(output);
... some more code (that shouldnt run until the script is complete)
我还可以运行以下脚本,该脚本将返回stderr:
var sh = require('shelljs');
... some code
var output = sh.exec('./someshellscript.sh', {silent:true}).stderr;
console.log(output);
... some more code (that shouldnt run until the script is complete)
但是,我希望在同步调用中同时接收stdout和stderr。这可能是我在这里错过的一些很明显的东西,但我无法解决它
我认为您过去可以在以前的版本中运行以下命令,但现在只返回undefined:
var sh = require('shelljs');
... some code
var output = sh.exec('./someshellscript.sh', {silent:true}).output;
console.log(output);
... some more code (that shouldnt run until the script is complete)
相关软件版本包括:
- Ubuntu:14.04.3 LTS
- 节点:4.4.4
- 净现值:2.15.1
- shelljs:0.7.0
const { stdout, stderr, code } = sh.exec('./someshellscript.sh', { silent: true })
非常感谢你的及时答复。完美:)显示代码:127/bin/sh:1:./nginx\u betaproduct.sh:未找到