Read the statement by Michael Teeuw here.
child_process won't execute
-
@sdetweil That is correct. It works up till that point.
-
@Temisola1 if you run this does it work from the terminal window?
import sys # Takes first name and last name via command # line arguments and then display them print("Output from Python") print("First name: " ) print("Last name: " )
testit.js
var spawn = require("child_process").spawn; // Parameters passed in spawn - // 1. type_of_script // 2. list containing Path of the script // and arguments for the script // E.g : http://localhost:3000/name?firstname=Mike&lastname=Will // so, first name = Mike and last name = Will var process = spawn('python3',["./testit.py"]); // req.query.firstname, // req.query.lastname] ); // Takes stdout data from script which executed // with arguments and send this data to res object process.stdout.on('data', (data)=> { console.log("received " +data); } )
works for me… (note python script path is ./, make sure u have right path to py file)
then do
node testit.js -
-
@sdetweil So I tried putting in the full path in my node_helper as opposed to relative path and that seemed to work. is there a way I can log the current directory in nodejs. It seems that’s the issue
-
@sdetweil after running successfully a few times it now returns Buffer 48 45 5c… or something that looks like hexadecimal code
-
@Temisola1 the node_helper doesn’t know where it is… but the Modulename does…
this.path
so, you can add that to the config info you send down in the typical
sendSocketNotification(“somevalue”, this.config)
to pass parameters to the node_helper
-
@Temisola1 said in child_process won't execute:
after running successfully a few times it now returns
u need to cleanup when the invoked process ends
process.on('exit', function() { if (x) { x.kill(); } });
-
-
Thank you all for all your wonderful suggestions. I’m able to run my python script successfully now. Thanks!