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变量,见附件:
在java application中调用process proc = runtime.getruntime().exec(“python xx.py”);是可以的【xx.py直接位于工程目录下面】
在tomcat中的servlet中使用process proc = runtime.getruntime().exec(“python xx.py”);时,开始是没反应。 排查结果应该是pyhon命令可以找到(或者直接输入e:\python\python.exe绝对路径) x.x.py 文件我是放在根目录下,故意把名字写错成xy.py.,结果都是没反应【仿佛这条语句没有执行】
=》应该是py文件找不到。我用了绝对路径搜索py文件。process proc = runtime.getruntime().exec(“python d:\xx.py”);这个倒是可以。
【目前总结 就是py文件的路径问题】
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2281893.html