Created
June 4, 2015 16:42
-
-
Save alayo/60683fbd23d2c6ec1925 to your computer and use it in GitHub Desktop.
Child process node
This file contains hidden or 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
| // 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