简体   繁体   中英

Meteor how to run server side python script

I have a Meteor app that needs to call a python script to do some stuff in the background. How can I get this to work? I've tried using child_process and exec, but I can't seem to get it to execute properly. Where should the script even be located?

Thanks

I have same problems and its solved use python-sheel an npm packages to run Python scripts from Node.js Install on meteor :

meteor npm install --save python-shell

There is simple usage :

var PythonShell = require('python-shell');

PythonShell.run('my_script.py', function (err) {
  if (err) throw err;
  console.log('finished');
});

If you want run with arguments and options :

var PythonShell = require('python-shell');

var options = {
  mode: 'text',
  pythonPath: 'path/to/python',
  pythonOptions: ['-u'],
  scriptPath: 'path/to/my/scripts',
  args: ['value1', 'value2', 'value3']
};

PythonShell.run('my_script.py', options, function (err, results) {
  if (err) throw err;
  // results is an array consisting of messages collected during execution
  console.log('results: %j', results);
});

here detail about python-shell https://github.com/extrabacon/python-shell Thanks extrabacon :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM