Skip to content

Instantly share code, notes, and snippets.

@bmeck
Created January 26, 2012 15:34
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 bmeck/1683299 to your computer and use it in GitHub Desktop.
Save bmeck/1683299 to your computer and use it in GitHub Desktop.
run `echo '1+1' | node parent.js`
var stdin = process.stdin;
stdin.resume();
stdin.on('data', function (data) {
console.log('GOT STDIN FROM PARENT', data + '')
})
//
// Keep it alive
//
setInterval(function() {}, 10000)
var spawn = require('child_process').spawn;
var code = '';
process.stdin.resume();
process.stdin.on('data', function (data) {code += data})
process.stdin.on('end', function () {
console.error('WRITING DATA')
var child = spawn('node',['child.js']);
child.stdout.on('data', function (data) {
console.log('CHILD.STDOUT', data + '')
})
child.stderr.on('data', function (data) {
console.log('CHILD.STDERR', data + '')
})
child.stdin.write(code)
})
//Just keep this alive...
setInterval(function () {}, 10000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment