Processbuilder to run commands from Java

I run a shell command from Java code using ProcessBuilder.start() I need feedback (or some kind of notification) when the command completes execution. It takes 10-15 seconds to complete the command. Is it possible to use ProcessBuilder?

+3
source share
2 answers

The start()ProcessBuilder method clearly states that it returns a Process whose API is here . This process has methods that can be called on it, including waitFor, which will wake the current thread when the process terminates. All you have to do is start the thread, give it this process and receive a signal when the process ends or after a timeout.

+4

, . waitFor() , , , 0 . , .

+4

All Articles