Skip to content

Instantly share code, notes, and snippets.

@piscisaureus
Created March 25, 2012 22:32
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 piscisaureus/5eeded9d874f11af3d94 to your computer and use it in GitHub Desktop.
Save piscisaureus/5eeded9d874f11af3d94 to your computer and use it in GitHub Desktop.
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