< prev index next >
test/testlibrary/com/oracle/java/testlibrary/ProcessTools.java
Print this page
rev 7753 : 8071909: Port testlibrary improvments in jdk/test to hotspot/test as required for DCMD test port
Reviewed-by:
@@ -184,23 +184,36 @@
return executeProcess(pb);
}
/**
* Executes a process, waits for it to finish and returns the process output.
+ * The process will have exited before this method returns.
* @param pb The ProcessBuilder to execute.
- * @return The output from the process.
+ * @return The {@linkplain OutputAnalyzer} instance wrapping the process.
*/
- public static OutputAnalyzer executeProcess(ProcessBuilder pb) throws Throwable {
+ public static OutputAnalyzer executeProcess(ProcessBuilder pb) throws Exception {
OutputAnalyzer output = null;
+ Process p = null;
+ boolean failed = false;
try {
- output = new OutputAnalyzer(pb.start());
+ p = pb.start();
+ output = new OutputAnalyzer(p);
+ p.waitFor();
+
return output;
} catch (Throwable t) {
+ if (p != null) {
+ p.destroyForcibly().waitFor();
+ }
+
+ failed = true;
System.out.println("executeProcess() failed: " + t);
throw t;
} finally {
- System.out.println(getProcessLog(pb, output));
+ if (failed) {
+ System.err.println(getProcessLog(pb, output));
+ }
}
}
/**
* Executes a process, waits for it to finish and returns the process output.
< prev index next >