Skip to content

Instantly share code, notes, and snippets.

@nasitra
Created October 31, 2015 02:34
Show Gist options
  • Select an option

  • Save nasitra/cf23536f6ae3c4bdf8d4 to your computer and use it in GitHub Desktop.

Select an option

Save nasitra/cf23536f6ae3c4bdf8d4 to your computer and use it in GitHub Desktop.
Interprocess communication of node.js and python
#!/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")
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