Java代码:
public class JavaExePython {
public static void run(String filePath, String param) throws IOException, InterruptedException {
String[] argv = {filePath, param};
PythonInterpreter.initialize(System.getProperties(), System.getProperties(), argv);
PythonInterpreter interpreter = new PythonInterpreter();
PySystemState sys = Py.getSystemState();
sys.path.add("C:\\workspace\\python\\mypython");
sys.path.add("C:\\Python27\\Lib\\site-packages");
interpreter.execfile(filePath);
}
}
Python 代码:
# -*- coding: utf-8 -*-
import json
import sys
from famiover.model.model import Model
from famiover.util.excelsheet import ExcelSheet
from famiover.util.excelutil import ExcelUtil
def thrall(param):
eu = ExcelUtil('filename.xls')
dicts = {
'r1': json.loads(param)
}
model_key = 'thrall'
excelsheet = ExcelSheet(eu, 'Thrall项目异常列表', dicts, Model, model_key)
# 保存至excel
eu.excelutil_save()
if __name__ == '__main__':
thrall(sys.argv[1])