Skip to content

Instantly share code, notes, and snippets.

@sam-github
Created January 10, 2014 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sam-github/8344689 to your computer and use it in GitHub Desktop.
Save sam-github/8344689 to your computer and use it in GitHub Desktop.
var spawn = require('child_process').spawn;
var open = require('fs').openSync;
console.log('process stdout', process.pid);
console.error('process stderr', process.pid);
if(process.env.i_am_child) {
console.error('child is alive');
} else {
var fd = open('out.txt', 'a');
process.env.i_am_child = true;
// Redirect stdout and stderr in child to the same file
var child = spawn(process.argv[0], process.argv.slice(1), {
stdio: ['ignore', fd, fd]
});
console.error('spawned child', child.pid);
child.on('exit', function(code,signal) {
console.error('child exit with', code, signal);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment