I'm using node.js to build a website, and I'm trying to execute a machine learning algorithm, but when I call a child process I recive the following message:
stderr: <Buffer 6e 74 6f 73 20 70 61 72 61 20 69 6e 73 74 61 6c 61 72 20 6e 61 20 4d 69 63 72 6f 73 6f 66 74 20 53 74 6f 72 65 20 6f 75 20 64 65 73 61 62 69 6c 69 74 ... 88 more bytes> child process exited with code 9009
Here is my code to execute the file:
router.post('/machineLearning', function (req, res) {
var childPython = spawn('python', ['../machineLearning/ml_teste.py'])
childPython.stdout.on('data', function (data) {
console.log("It worked")
})
childPython.stderr.on('data', (data) => {
console.error('stderr: ', data)
})
childPython.on('close', (code) => {
console.log("child process exited with code ", code)
})
})
And here is the file I'm trying to execute:
import sys
print("Output from Python: Hellow World")
What is wrong with my code?
Thank you so much for your attention!
CodePudding user response:
The status code means file not found. Please provide the correct path to the spawn method. Also, change the buffer o/p to string like this :
childPython.stderr.on('data', (data) => {
console.error('stderr: ', data.toString('utf8'));
})