Created
December 18, 2012 16:26
-
-
Save isaacs/4329419 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
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