在Grunt中显示输出为命令运行?
在这里,我没有输出,命令永远运行:
grunt.registerTask('serve', function () { var done = this.async(); grunt.util.spawn({ cmd: 'jekyll', args: ['serve'], stdio: 'inherit' }, function (err, res, exit_code) { res.stdout && console.info(res.stdout); exit_code && console.error(res.stderr); done(err); }); });
我想输出(和命令运行,直到错误或中断)。
尝试这个:
grunt.registerTask('serve', function(){ var done = this.async(); var child = grunt.util.spawn({ cmd: 'jekyll', args: ['serve'] }, function(){ ... }); child.stdout.pipe(process.stdout); child.stderr.pipe(process.stderr); });
请参阅: Grunt衍生的进程不捕获输出
感谢你的回答,@ Lihau-Tan接近了正确的一个。
结合这个答案和我的尝试,我想出了这个解决scheme:
grunt.registerTask('serve', function () { var child = grunt.util.spawn({ cmd: 'jekyll', args: ['serve', '-P', process.env.PORT || 4001], stdio: 'inherit' }, this.async()); child.stdout.pipe(process.stdout); child.stderr.pipe(process.stderr); });
你可以使用grunt日志
以下function可用
grunt.log.write(msg) grunt.log.writeln([msg]) grunt.log.error([msg]) grunt.log.errorlns(msg) grunt.log.ok([msg]) grunt.log.oklns(msg) grunt.log.subhead(msg) grunt.log.writeflags(obj, prefix) grunt.log.debug(msg)