in surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java [342:413]
ProcessInfo execute(String... command) {
ProcessBuilder processBuilder = new ProcessBuilder(command);
Process process = null;
ProcessInfo processInfo = INVALID_PROCESS_INFO;
StringBuilder out = new StringBuilder(64);
out.append(join(" ", command)).append(NL);
Path stdErr = null;
try {
stdErr = SureFireFileManager.createTempFile("surefire", null).toPath();
processBuilder.redirectError(stdErr.toFile());
if (IS_OS_HP_UX) // force to run shell commands in UNIX Standard mode on HP-UX
{
processBuilder.environment().put("UNIX95", "1");
}
process = processBuilder.start();
destroyableCommands.add(process);
Scanner scanner = new Scanner(process.getInputStream(), charset);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
out.append(line).append(NL);
processInfo = consumeLine(line.trim(), processInfo);
}
checkValid(scanner);
int exitCode = process.waitFor();
boolean isError = Thread.interrupted() || isStopped();
if (exitCode != 0 || isError) {
out.append("<<exit>> <<")
.append(exitCode)
.append(">>")
.append(NL)
.append("<<stopped>> <<")
.append(isStopped())
.append(">>");
DumpErrorSingleton.getSingleton().dumpText(out.toString());
}
return isError ? ERR_PROCESS_INFO : (exitCode == 0 ? processInfo : INVALID_PROCESS_INFO);
} catch (Exception e) {
if (!(e instanceof InterruptedException
|| e instanceof InterruptedIOException
|| e.getCause() instanceof InterruptedException)) {
DumpErrorSingleton.getSingleton().dumpText(out.toString());
DumpErrorSingleton.getSingleton().dumpException(e);
}
//noinspection ResultOfMethodCallIgnored
Thread.interrupted();
return ERR_PROCESS_INFO;
} finally {
if (process != null) {
destroyableCommands.remove(process);
closeQuietly(process.getInputStream());
closeQuietly(process.getErrorStream());
closeQuietly(process.getOutputStream());
}
if (stdErr != null) {
try {
String error = new String(readAllBytes(stdErr)).trim();
if (!error.isEmpty()) {
DumpErrorSingleton.getSingleton().dumpText(error);
}
delete(stdErr);
} catch (IOException e) {
// cannot do anything about it, the dump file writes would fail as well
}
}
}
}