Returns the error message of a process. @param process process @param timeout time out in milliseconds @return error message or null
(final Process process, final int timeout)
| 306 | * @return error message or {@code null} |
| 307 | */ |
| 308 | public static String error(final Process process, final int timeout) { |
| 309 | final int wait = 200, to = Math.max(timeout / wait, 1); |
| 310 | for(int c = 0; c < to; c++) { |
| 311 | try { |
| 312 | final int exit = process.exitValue(); |
| 313 | if(exit == 1) return new IOStream(process.getErrorStream()).readString(); |
| 314 | break; |
| 315 | } catch(final IllegalThreadStateException ex) { |
| 316 | debug(ex); |
| 317 | // process is still running |
| 318 | Performance.sleep(wait); |
| 319 | } catch(final IOException ex) { |
| 320 | // return error message of exception |
| 321 | return ex.getLocalizedMessage(); |
| 322 | } |
| 323 | } |
| 324 | return null; |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * Returns the contents of a property resource. |
no test coverage detected