Index: TesterOpenSSL.java =================================================================== --- TesterOpenSSL.java (revision 1615499) +++ TesterOpenSSL.java (working copy) @@ -180,7 +180,7 @@ t2.start(); try { - p.waitFor(2, TimeUnit.SECONDS); + waitForProcess(p, 2); } catch (InterruptedException e) { throw new IOException(e); } @@ -193,6 +193,24 @@ return stdout.getText().trim(); } + private static boolean waitForProcess(Process p, int seconds) throws InterruptedException { + long startTime = System.nanoTime(); + long rem = TimeUnit.SECONDS.toNanos(seconds); + + do { + try { + p.exitValue(); + return true; + } catch(IllegalThreadStateException ex) { + if (rem > 0) { + Thread.sleep(Math.min(TimeUnit.NANOSECONDS.toMillis(rem) + 1, 100)); + } + } + rem = TimeUnit.SECONDS.toNanos(seconds) - (System.nanoTime() - startTime); + } while (rem > 0); + return false; + } + private static class InputStreamToText implements Runnable { private final ByteArrayOutputStream baos = new ByteArrayOutputStream();