Skip to content

Instantly share code, notes, and snippets.

@bmeck bmeck/child.js
Created Jan 26, 2012

Embed
What would you like to do?
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
You can’t perform that action at this time.