Grunt衍生的过程不捕获输出 [英] Grunt spawned process not capturing output

查看:177
本文介绍了Grunt衍生的过程不捕获输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Grunt生成了一个进程,但没有任何写入输出流的东西(例如 console.log )正在控制台中显示。

I have spawned a process using Grunt, but nothing that is written to the output stream (such as console.log) is being displayed in the console.

我希望Grunt显示流程中的任何输出。

I would like Grunt to display any output from the process.

grunt.util.spawn(
  { cmd: 'node'
  , args: ['app.js']
  , opts:
      { stdio:
          [ process.stdin
          , process.stout
          , process.stderr
          ]
      }
  })


推荐答案

尝试将其设置为 opts:{stdio:'inherit'} 。否则,您可以管输出:

Try setting it to opts: {stdio: 'inherit'}. Otherwise you can pipe the output:

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

或者如果您想修改输出:

Or if you want to modify the output:

child.stdout.on('data', function(buf) {
    console.log(String(buf));
});

这篇关于Grunt衍生的过程不捕获输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆