Fix issue "java.lang.IllegalThreadStateException: process hasn't exited"
by waiting for the process to complete before calling exitValue().