I am running a shell command from Java code using ProcessBuilder.start()
I need a call-back (or some sort of notification) when the command finishes execution. The command takes 10-15 seconds to execute. Is it possible using ProcessBuilder
?
The start()
method of ProcessBuilder clearly states it returns a Process, whose API is here. That Process has methods that can be called on it, including waitFor, which will wake up the current thread when the Process has finished. All you need to do is start a thread, give it this process and have it signal when the Process finishes, or after a timeout.