Skip to content

Instantly share code, notes, and snippets.

@alayo
Created June 4, 2015 16:42
Show Gist options
  • Select an option

  • Save alayo/60683fbd23d2c6ec1925 to your computer and use it in GitHub Desktop.

Select an option

Save alayo/60683fbd23d2c6ec1925 to your computer and use it in GitHub Desktop.
Child process node
// Require spawn from the child process module
var spawn = require('child_process').spawn;
// Run node with the child.js file as an argument
var child = spawn('node', ['addon']);
// Send data to the child process via its stdin stream
//child.stdin.write("Hello there!");
child.stdout.setEncoding('utf8');
// Listen for any response from the child:
child.stdout.on('data', function (data) {
var str = data.toString();
io.emit('send cmd', str);
});
// Listen for any errors:
child.stderr.on('data', function (data) {
console.log('There was an error: ' + data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment