Skip to content

Commit

Permalink
Print output when executing commands when exit code != 0 (#540)
Browse files Browse the repository at this point in the history
Print output when executing commands when exit code != 0
  • Loading branch information
Madrigal authored Sep 27, 2024
1 parent ec6d6f9 commit c175324
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public static void execute(File workingDir, String... command) throws Exception
public void execute() throws Exception {
int exitCode;
Process child;
var output = new StringBuilder();
try {
var cmdArray = new String[command.size()];
command.toArray(cmdArray);
Expand All @@ -73,12 +74,16 @@ public void execute() throws Exception {
InputStreamReader(child.getErrorStream(), Charset.defaultCharset()));

String s;
output.append("stdout: ");
while ((s = stdOut.readLine()) != null) {
LOGGER.info(s);
output.append(s);
}
stdOut.close();
output.append(" stderr: ");
while ((s = stdErr.readLine()) != null) {
LOGGER.warning(s);
output.append(s);
}
stdErr.close();
} catch (Exception e) {
Expand All @@ -87,7 +92,7 @@ public void execute() throws Exception {

if (exitCode != 0) {
throw new Exception("Command existed with non-zero code, " + command
+ ", status code: " + exitCode);
+ ", status code: " + exitCode + " output: " + output);
}
}

Expand Down

0 comments on commit c175324

Please sign in to comment.