Node.js child_process.spawn is unable to launch python process -
i have written following code spawn python process. able launch other processes not python. tried reinstalling python , node still no luck. able run python command line. please help.
const spawn = require("child_process").spawn; var process = spawn('python',[ 'd:/python_script.py']); var responsedata = ""; process.stdout.setencoding('utf-8'); process.stdout.on('data', function (data){ responsedata += data.tostring(); }); process.stdout.on('end',function(data){ console.log(json.stringify(responsedata)); });
using node 64 bit v8.2.1
python script using:
if __name__ == '__main__': import sys print("hello") f = open('d:/myfile.txt', 'w') f.write('hi there\n') # python convert \n os.linesep f.close() sys.stdout.flush()
even spawn('python'); not launching python window
i have tried giving absolute path of python.exe.
change
console.log(json.stringify(responsedata));
to
console.log(responsedata);
and add
process.stderr.on('data', function (data){ responsedata += data.tostring(); });
below
process.stdout.on('data', function (data){ responsedata += data.tostring(); });
Comments
Post a Comment