Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created December 18, 2012 16:26
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 isaacs/4329419 to your computer and use it in GitHub Desktop.
Save isaacs/4329419 to your computer and use it in GitHub Desktop.
if (process.argv[2] === 'child')
child();
else
parent();
function parent() {
var spawn = require('child_process').spawn;
var node = process.execPath;
var child = spawn(node, [__filename, 'child']) //, {stdio:'inherit'});
console.log('pid=%d', child.pid);
child.stdout.on('data', function(c) {
console.log(("stdout: " + c).trim());
});
child.stderr.on('data', function(c) {
console.error(('stderr: ' + c).trim());
});
child.on('exit', function() {
console.log('child exit');
});
}
function child() {
console.log('hello');
console.log(process.stdout);
setTimeout(function() { process.exit() }, 1000)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment