在流星方法使用下面的代码:
'methodName':function(){
new Fiber(function(){
console.log('test python file');
var file_path = process.env.PWD + "/path_to_file/hello.py";
exec("python " + file_path, function (error, stdout, stderr) {
if (error) console.log('error'+error);
if (stdout) console.log('stdout'+stdout);
if (stderr) console.log('stderr'+stderr);
});
}).run();
}
这里stdout
包含Python代码的输出。你不能直接使用从python生成的图表,因为它很难整合,但是,你可以将数据发送到meteor并使用meteor在客户端使用d3js或plot.ly等库生成图。
输出数据可以是矩阵或JSON,或者甚至可以是流星随后读取并执行操作的文件。
编辑1:示例模板使用它
'methodName':function(){
new Fiber(function(){
console.log('test python file');
var file_path = process.env.PWD + "/path_to_file/hello.py";
exec("python " + file_path, function (error, stdout, stderr) {
if (error) console.log('error'+error);
else if (stdout) return stdout;
else if (stderr) console.log('stderr'+stderr);
});
}).run();
}
//在助手
'helper1': function(){
return Meteor.call('methodName');
}
//在HTML中
{{heplper1}}
谢谢,我会给它一个尝试,走着瞧吧。 – RolandDeschain
嗨@Ankit,我让它工作..但我仍然不知道如何使用流星模板中的标准输出数据。任何想法?谢谢 – RolandDeschain
嗨@RolandDeschain,我用一个例子编辑了答案。 – Ankit