java直接调用python脚本的例子
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) {
try {
System.out.println("start");
Process pr = Runtime.getRuntime().exec("python test.py");
BufferedReader in = new BufferedReader(new InputStreamReader(
pr.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
pr.waitFor();
System.out.println("end");
} catch (Exception e) {
e.printStackTrace();
}
}
}
如果在eclipse中直接运行报如下错误:
java.io.IOException: Cannot run program "python": CreateProcess error=2
则配置Run Configuration中的Enviroment,增加PATH变量,见下图:

相关文章
tensorflow可视化Keras框架中Tensorboard使用示例
这篇文章主要为大家介绍了tensorflow可视化Keras框架中Tensorboard使用示例,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2022-05-05
使用python画出逻辑斯蒂映射(logistic map)中的分叉图案例
这篇文章主要介绍了使用python画出逻辑斯蒂映射(logistic map)中的分叉图案例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2020-12-12
Python入门教程(三十一)Python的Try和Except
这篇文章主要介绍了Python入门教程(三十一)Python的Try Except,当我们调用Python并发生错误或异常时,通常会停止并生成错误消息,2023-05-05
可以使用try语句处理这些异常,需要的朋友可以参考下
详解Python中的Numpy、SciPy、MatPlotLib安装与配置
这篇文章主要介绍了详解Python中的Numpy、SciPy、MatPlotLib安装与配置,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-11-11


最新评论