I'm trying to communicate between node.js and python-shell. I was able to recieve data from python-shell-object but when I try to send a message to the python-shell it crashes.
my app.js:
var PythonShell = require('python-shell');
var options = {
scriptPath: '/home/pi/python'
};
var pyshell = new PythonShell('test.py', options, {
mode: 'text'
});
pyshell.stdout.on('data', function(data) {
pyshell.send('go');
console.log(data);
});
pyshell.stdout.on('data2', function(data) {
pyshell.send('OK');
console.log(data);
});
pyshell.end(function(err) {
if (err) throw err;
console.log('End Script');
});
and my test.py:
import sys
print "data"
for line in sys.stdin:
print "data2"
I basically want to have communication in a chronolical way:
- recieve "data" from python
- send "go" to python
- recieve "data2" from python
Another Question: In the tutorial on https://github.com/extrabacon/python-shell it is written that you have to write pyshell.on() to wait for data while in the source-code the author writes pyshell.stdout.on(). Why is that?
Thanks!!! (wrong indention in python corrected)