public static int waitForExitProcess ( Pointer hProcess ) throws InterruptedException { while ( true ) { if ( Thread . interrupted ( ) ) throw new InterruptedException ( ) ; Kernel32 . INSTANCE . WaitForSingleObject ( hProcess , 1000 ) ; IntByReference exitCode = new IntByReference ( ) ; exitCode . setValue ( - 1 ) ; Kernel32 . INSTANCE . GetExitCodeProcess ( hProcess , exitCode ) ; int v = exitCode . getValue ( ) ; if ( v != Kernel32 . STILL_ACTIVE ) { return v ; } } }
Given the process handle waits for its completion and returns the exit code .