Run external program from Java, read output, allow interruption

前端 未结 5 1122
孤独总比滥情好
孤独总比滥情好 2020-11-29 08:18

I want to launch a process from Java, read its output, and get its return code. But while it\'s executing, I want to be able to cancel it. I start out by launching the proce

5条回答
  •  抹茶落季
    2020-11-29 09:22

    I recommend checking out Apache Commons Exec to avoid recreating the wheel. It has some nice features like choosing between synchronous vs. asynchronous execution, as well as a standard solution to spawning a watchdog process that can help in timing out the execution in case it gets stuck.

提交回复
热议问题