-
-
Save piscisaureus/5eeded9d874f11af3d94 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 process | |
// Echo all stdin data. | |
process.stdin.on('data', function(s) { | |
console.log("Child received: " + s); | |
}); | |
process.stdin.setEncoding('utf-8'); | |
process.stdin.resume(); | |
} else { | |
// Parent process | |
// Spawn a child process, make stdin a pipe and inherit stdout/stderr. | |
var child = require('child_process').spawn(process.execPath, | |
[process.argv[1], 'child'], | |
{ customFds: [-1, 1, 2 ] }); | |
setInterval(function() { | |
console.log("Parent: sending 'A' to child"); | |
child.stdin.write("A"); | |
}, 1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment