我已经使用 Grunt 生成了一个进程,但是控制台中没有显示任何写入输出流的内容(例如 console.log
)。
我希望 Grunt 显示进程的任何输出。
grunt.util.spawn(
{ cmd: 'node'
, args: ['app.js']
, opts:
{ stdio:
[ process.stdin
, process.stout
, process.stderr
]
}
})
最佳答案
尝试将其设置为 opts: {stdio: 'inherit'}
。否则,您可以通过管道输出:
var child = grunt.util.spawn({
cmd: process.argv[0], // <- A better way to find the node binary
args: ['app.js']
});
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
或者如果你想修改输出:
child.stdout.on('data', function(buf) {
console.log(String(buf));
});
关于node.js - Grunt 产生的进程没有捕获输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15044307/