6

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

4
  • 1
    Seems like here is what are you looking for Commented Apr 6, 2015 at 23:50
  • I've tried using that, but where should my script be located? Commented Apr 7, 2015 at 0:19
  • away from the scope of the meteor project outside the project would be a nice place, btw did you get a solution for the other 2 questions? about mongo and python? there is not to much information over here to accomplish that, if you find a workaround please post it =D Commented Apr 7, 2015 at 0:22
  • Hmm I still don't think it's working... in the exec function, what exactly am I putting? Is it a python command? and how can I tell if it was successful? Commented Apr 7, 2015 at 0:31

1 Answer 1

3

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 :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.