Created
November 10, 2011 07:20
-
-
Save shinout/1354330 to your computer and use it in GitHub Desktop.
redirecting stdout goes wrong when writing stdout from multi-processes
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
var fork = require("child_process").fork; | |
var workers = []; | |
for (var i=0; i<6; i++) { (function(i) { | |
workers[i] = fork(__dirname + "/worker.js"); | |
workers[i].send(i); | |
})(i) } |
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
process.on("message", function(msg) { | |
for (var i=1; i<=100; i++) { | |
console.log(msg, i); | |
} | |
process.stdout.end(); | |
}); | |
process.stdout.on("close", function() { | |
process.exit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ node main.js > filename
$ wc filename
570 1140 2801 filename
(expects 600)
$ node main.js | wc
600 1200 2952
$ node main.js | cat > filename
$ wc filename
600 1200 2952