I'm using NodeJS, and a Python script.
I need to get results from my python script, for that, I use Python-Shell. See the documentation at this link :
github.com/extrabacon/python-shell
I can get prints by using pythonShell.on and pythonShell.end.
The problem is that I can't send args with this method
Then I use pythonShell.run!
I can send args but it doesn't return prints while it should ....
Can you help to get my prints ?
You can see my short code below, it's a simple code, just to make it work.
var pythonShell = require('python-shell');
app.post('/index/generator/',urlencodedParser, function (req,res){
var options = {
mode: 'JSON',
pythonOptions: ['-u'],
scriptPath: './generator',
args: ['hello','bye']
};
pythonShell.run('generator.py', options, function (err, results) {
if (err) throw err;
console.log("Message %j ",results);
});
})
Here the python code :
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
print(sys.argv[1]+' '+sys.argv[2])