I'm trying to run a python function with arguments from node.js.
When I run process.stdout.on nothing happens. Here's the full code:
Node.js
app,get('/', async (req, res) => {
const spawn = require('child_process').spawn; // Should this be called every time, or can I just put it with my other `require` statements?
var process = await spawn('python', [
'../../python/hello.py',
'Hello',
'World'
]);
process.stdout.on('data', function(data) {
console.log(data.toString());
// res.send(data.toString()); // When I do this, the website never loads
});
res.send('test');
});
Python
import sys
print("Output from Python")
print("First name: " + sys.argv[1])
print("Last name: " + sys.argv[2])
I'm running the node app via nodemon, and I'm not seeing any results. (I'm new to python, so I don't know if anything has to be running while the node app is running.
It doesn't seem like the python file is loading. How can I get it to load?