Java 中执行Python Runtime 方式实现
来源:互联网 发布:opencv 匹配优化 编辑:程序博客网 时间:2024/05/22 01:26
前提:
window 安装了python
并且配置好了环境变量
一般两种方法:
引入 org.python 包 jPython 这个包
这个有两种使用方式:如下:
1.直接执行python脚本PythonInterpreter interpreter = new PythonInterpreter();interpreter.exec("print("123")"); ///执行python脚本2.执行python .py文件PythonInterpreter interpreter = new PythonInterpreter(); InputStream filepy = new FileInputStream("/root/Desktop/demo.py"); interpreter.execfile(filepy); ///执行python py文件filepy.close();
2.还有一种方式就是Runtime : 这个方式相对来靠谱:
Process proc = Runtime.getRuntime().exec("python /root/Desktop/demo.py"); proc.waitFor();
看个实例:
Process process; try { process = Runtime.getRuntime().exec("python D:\\datax\\bin\\datax_3.py D:\\datax\\bin\\oraclejson2localfile.json ");// process.waitFor(); BufferedReader stdOut=new BufferedReader(new InputStreamReader(process.getInputStream())); String s; while((s=stdOut.readLine())!=null){ System.out.println(s); } int result=process.waitFor(); process.destroy(); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); }
阅读全文
0 0
- Java 中执行Python Runtime 方式实现
- java使用Runtime.getRuntime来执行python脚本
- JAVA中的饿汉式和饱汉式单例模式及jdk中Runtime类的单例模式实现方式详解
- Java执行Runtime.getRuntime().exec()
- 使用Runtime.getRuntime().exec()在java中调用python脚本
- java中runtime异常
- Java中Runtime对象
- 在java中调用/执行python方法
- python中执行shell命令的几种方式
- 实现在Java中执行python代码或py脚本(可传参数)
- Andorid利用sserver/runtime实现java执行linux程序或脚本
- java中多线程实现方式
- java中反射实现方式
- java 使用Runtime.getRuntime().execx 执行失败
- Java 执行运行时命令 Runtime
- java使用Runtime.exec执行linux命令
- java使用Runtime.exec执行linux命令
- java使用Runtime.exec执行linux命令
- JS中连等赋值操作使用注意事项(a=b=c)
- 使用Angular Route导航
- bootstrap-select 无法选中 的问题
- 1.python基础要点(三)
- nginx基本配置
- Java 中执行Python Runtime 方式实现
- 湘潭市赛 有感
- 215. Kth Largest Element in an Array
- 使用thinkPHP3.2.3从一个页面向另一个页面传值,动态变量模板展示,从session获取变量在模板展示
- 对于带头结点的单链表的相关操作
- eclipse安装反编译插件
- Python 30分钟入门
- Java VisualVM插件地址
- 切图小技巧