[英]Meteor how to run server side python script
我有一个Meteor应用程序,需要调用python脚本在后台执行一些操作。 我怎样才能让它发挥作用? 我已经尝试过使用child_process和exec,但我似乎无法让它正确执行。 脚本应该放在哪里?
谢谢
我有同样的问题,它解决了使用python-sheel和npm包从Node.js运行Python脚本在meteor上安装:
meteor npm install --save python-shell
有一个简单的用法:
var PythonShell = require('python-shell');
PythonShell.run('my_script.py', function (err) {
if (err) throw err;
console.log('finished');
});
如果你想运行参数和选项:
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);
});
这里有关python-shell的详细信息https://github.com/extrabacon/python-shell谢谢extrabacon :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.