in src/main/java/pemja/utils/CommonUtils.java [168:192]
private String execute(String[] commands) throws IOException {
ProcessBuilder pb = new ProcessBuilder(commands);
pb.redirectErrorStream(true);
Process p = pb.start();
InputStream in = new BufferedInputStream(p.getInputStream());
StringBuilder out = new StringBuilder();
String s;
try (BufferedReader br = new BufferedReader(new InputStreamReader(in))) {
while ((s = br.readLine()) != null) {
out.append(s).append("\n");
}
}
try {
if (p.waitFor() != 0) {
throw new IOException(
String.format(
"Failed to execute the command: %s\noutput: %s",
String.join(" ", commands), out));
}
} catch (InterruptedException e) {
// Ignored. The subprocess is dead after "br.readLine()" returns null, so the call of
// "waitFor" should return intermediately.
}
return out.toString();
}