I'm trying to spawn a child process to run a python script from Node. I have the following request that comes in:
/webcrawler?source=http://www.pygamers.com&method=BFS&nodeCount=3&depth=0&keyword=game
I have verified that my params are coming in correctly. Here is my code set up to handle the request in app.js
:
app.get('/webcrawler', function(req, res){
var python = require('child_process').spawn(
'python',
["WebCrawler/Webcrawler.py"
, req.query.source
, req.query.method
, req.query.nodeCount
, req.query.depth
, req.query.keyword]
);
var output = "";
python.stdout.on('data', function(data){ output += data });
python.on('close', function(code){
if (code !== 0) {
return res.send(500, code);
}
return res.send(200, output);
});
});
I am calling my Python script, Webcrawler.py
which is in the WebCrawler directory. The WebCrawler directory is in the same directory as app.js
.
However, this request is giving me a 500, and I haven't been able to figure out why. It seems like I must be generating the child process incorrectly. I used this answer as a model for doing so.