[英]Java process.getRuntime().exec() never stop his job
Hello guys im writing a web app in java with servlet, but i need for a job to use python, so im using Process.getRuntime().exec() for call the script.大家好,我正在用 servlet 用 Java 编写一个 Web 应用程序,但我需要一份工作来使用 python,所以我使用 Process.getRuntime().exec() 来调用脚本。 My web app is a survey and between client compile it we take a photo of him.
我的网络应用程序是一项调查,在客户端编译它之间我们给他拍了一张照片。 I need python for deepface, for detection his emotion, and write all the results in a pdf file (what he choose, photos and detection of emotion result).
我需要python for deepface,检测他的情绪,并将所有结果写在一个pdf文件中(他选择什么,照片和情绪检测结果)。 For 7 question in the survey the script works fine, when i put 8 question he never stop his job (the script working when isn't called from java i tested it).
对于调查中的 7 个问题,脚本工作正常,当我提出 8 个问题时,他从不停止他的工作(脚本在没有从 java 调用时工作,我对其进行了测试)。 Can you help me for understand how i can find the error?
你能帮我理解我如何找到错误吗? This process has got a limit of resources or something like that?
这个过程有资源限制之类的吗?
Process p = Runtime.getRuntime().exec("python "+rootPath+"\\DeepFaceLearning\\TestFace.py "+nomeFile);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
String temp ="";
while((temp = stdInput.readLine()) != null) {
System.out.println(temp);
}
For python the script is very long, but i think the problem is java beacuse he works fine when i run the script from command line with 40 questions.对于python,脚本很长,但我认为问题是java,因为当我从命令行运行脚本时,他工作正常,有40个问题。 I need to add 21 question in total.
我总共需要添加 21 个问题。 Script python:
脚本蟒蛇:
Edit: java enter into script but don't complete all the job.编辑:java 进入脚本但没有完成所有的工作。
If the your python is working for 7 the same way as for 8 question, you could try to read the inputstream in other Thread
.如果您的 python 以与 8 问题相同的方式为 7 工作,您可以尝试读取其他
Thread
。
Like:喜欢:
...
new Thread(new Runnable(){
@Override
public void run(){
BufferedReader stdInput = new BufferedReader(newInputStreamReader(p.getInputStream()));
String temp ="";
while((temp = stdInput.readLine()) != null) {
System.out.println(temp);
}}).start();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.