Created
January 10, 2014 00:20
-
-
Save sam-github/8344689 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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