Grunt spawned process not capturing output

房东的猫 提交于 2019-11-30 01:08:38

问题


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.

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
          ]
      }
  })

回答1:


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


来源:https://stackoverflow.com/questions/15044307/grunt-spawned-process-not-capturing-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!