public static void waitFor ( Process proc , long timeout , TimeUnit unit ) throws CommandTimeoutException { try { boolean finishedInTime = proc . waitFor ( timeout , unit ) ; if ( ! finishedInTime ) { proc . destroyForcibly ( ) ; throw new CommandTimeoutException ( ) ; } } catch ( InterruptedException e ) { Thread . currentThread ( ) . interrupt ( ) ; } }
Waits for the process to terminate or throws an exception if it fails to do so within the given timeout .