在 nodejs 脚本中,我有以下代码同步调用并从我正在调用的 shell 脚本返回标准输出:
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}).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
- npm:2.15.1
- shelljs:0.7.0
任何帮助表示感谢。