Java执行Python脚本并传参
2017-02-04 00:00
323 查看
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])
相关文章推荐
- 在Java中动态传参调用Python脚本
- Java调用Python脚本(需要传参)
- java 利用Runtime.getRuntime().exec()调用python脚本并传参
- java动态传参调用python脚本
- 利用python执行shell脚本 并动态传参 及subprocess基本使用
- 原生js+java执行python脚本+Long类型list集合转为long集合
- java/linux执行Python脚本
- java 执行python脚本(出现由于python导入了其他包而无法成功执行的问题)
- java 利用Runtime.getRuntime().exec()调用python脚本并传参
- Java实现的执行python脚本工具类示例【使用jython.jar】
- java传参调用python脚本得到爬取图片路径
- 实现在Java中执行python代码或py脚本(可传参数)
- 在Java中动态传参调用Python脚本
- java调用python脚本传参
- java使用Runtime.getRuntime来执行python脚本
- python 获取当前当前目录 脚本目录 被执行脚本目录
- Bash下如何执行python脚本文件
- javacript 脚本的执行顺序
- 使用py2exe打包python脚本为exe可执行程序
- wsdl?java的执行脚本