ProcessBuilder and Process.waitFor(), how long does it wait?

前端 未结 3 830
闹比i
闹比i 2020-12-16 16:00

I am executing an .exe-file from java, using the ProcessBuilder class and the Process class. To explain what I am doing:

 builder = new ProcessBuilder(comman         


        
3条回答
  •  独厮守ぢ
    2020-12-16 16:26

    Your current execution thread will be blocked on process.waitFor() until process is terminated (i.e. execution finished). Source here

    Also note that if process is already terminated : waitFor() will not be blocked. I don't know if the code you put in your question is exactly what you run... but you must be careful and re-create a new instance of Process for every execution of your script (i.e. not just calling start multiple times on the same Process: it won't work after first execution)

提交回复
热议问题