Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

processbuilder to run commands from Java

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?

like image 826
code4fun Avatar asked Sep 05 '25 22:09

code4fun


1 Answers

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.

like image 155
Nathaniel Ford Avatar answered Sep 08 '25 23:09

Nathaniel Ford