2016-04-18 60 views
1

在这里我没有得到任何输出,并命令将永远运行下去:作为命令运行时在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); 
    }); 
}); 

我想输出(和命令运行,直到错误或中断)。

回答

1

试试这个:

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 spawned process not capturing output

0

您可以使用grunt log

提供以下功能

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) 
1

感谢您的答案,@ Lihau谭接近到正确的一个。

结合这个问题的答案我的尝试,我想出了这个解决方案:

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); 
}); 
相关问题