Tuesday, 23 May 2017

node child_process gives valid output in stderr for mongodump

I'm executing mongodump command from nodejs child_process.

I have tried both exec and spawn, but the progress printed by mongodump is hitting the data event of stderr instead of stdout

var exec = require('child_process').exec,
    ls    = exec('mongodump --gzip --archive="/home/test-machine/test.archive" --db myDB');

ls.stdout.on('data', function (data) {
  console.log('stdout: ' + data.toString());
});

ls.stderr.on('data', function (data) {
  console.log('stderr: ' + data.toString());
});

ls.on('exit', function (code) {
  console.log('child process exited with code ' + code.toString());
});

The mongodump is not crashing, or throwing any error, its executing as it should. But somehow nodejs is treating the output as stderr



via Dushyant Bangal

No comments:

Post a Comment