user1082754
user1082754

Reputation:

Grunt spawned process not capturing output

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

Upvotes: 15

Views: 6236

Answers (1)

Kyle Robinson Young
Kyle Robinson Young

Reputation: 13762

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

Upvotes: 36

Related Questions