Created
July 30, 2012 20:01
-
-
Save cowboy/3209657 to your computer and use it in GitHub Desktop.
Node.js 0.8: trying to see a difference between child_process "exit" and "close" events
This file contains hidden or 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
function parent() { | |
var n = 0; | |
var spawn = require('child_process').spawn; | |
var child = spawn(process.execPath, [module.filename, true]); | |
child.stdout.on('data', function(buf) { | |
n += String(buf).length; | |
}); | |
child.on('exit', function() { | |
console.log('exit', n); | |
}); | |
child.on('close', function() { | |
console.log('close', n); | |
}); | |
} | |
function child() { | |
var n = 0 | |
var id = setInterval(function() { | |
if (++n > 1000) { | |
clearInterval(id); | |
} else { | |
process.stdout.write(Array(100001).join(1234567890)); | |
} | |
}, 1); | |
} | |
if (process.argv[2]) { | |
child(); | |
} else { | |
parent(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can't get it to be different. Meh.