[英]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.