Created
October 31, 2015 02:34
-
-
Save nasitra/cf23536f6ae3c4bdf8d4 to your computer and use it in GitHub Desktop.
Interprocess communication of node.js and python
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
| #!/usr/bin/env python | |
| # -*- coding:utf-8 -*- | |
| import sys | |
| sys.stdout.write("run\n") | |
| sys.stdout.write(">> ") | |
| for line in iter(sys.stdin.readline, ""): | |
| if line.strip() != "": | |
| sys.stdout.write("from python: " + line) | |
| sys.stdout.write(">> ") | |
| sys.stdout.write("\n") |
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
| var spawn = require('child_process').spawn; | |
| var child = spawn('python', ['-u', 'child.py']); | |
| child.stdout.on('data', function(data) { | |
| process.stdout.write(data); | |
| }); | |
| child.stdout.on('close', function() { | |
| process.stdout.write('close'); | |
| }); | |
| child.kill(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment