diff --git a/spec/src/main/java/cloud/xcan/angus/spec/process/ProcessCommand.java b/spec/src/main/java/cloud/xcan/angus/spec/process/ProcessCommand.java index af2c7fdc..d8208606 100644 --- a/spec/src/main/java/cloud/xcan/angus/spec/process/ProcessCommand.java +++ b/spec/src/main/java/cloud/xcan/angus/spec/process/ProcessCommand.java @@ -147,17 +147,18 @@ public static CommandResult runNativeCmd(String[] cmdToRunWithArgs, Map result = new ArrayList<>(); try { - Scanner s = new Scanner(p.getInputStream(), UTF_8).useDelimiter(System.lineSeparator()); - while (s.hasNext()) { - result.add(s.next()); + try (Scanner s = new Scanner(p.getInputStream(), UTF_8).useDelimiter(System.lineSeparator())) { + while (s.hasNext()) { + result.add(s.next()); + } + // Block the current thread until the child process completes execution. + exitCode = p.waitFor(); + } catch (Exception e) { + log.error("Problem reading output by command `{}`: {}", Arrays.toString(cmdToRunWithArgs), + e.getMessage()); + execSuccess = false; + result.add(e.getMessage()); } - // Block the current thread until the child process completes execution. - exitCode = p.waitFor(); - } catch (Exception e) { - log.error("Problem reading output by command `{}`: {}", Arrays.toString(cmdToRunWithArgs), - e.getMessage()); - execSuccess = false; - result.add(e.getMessage()); } boolean success = execSuccess && exitCode == 0; if (onlyMatchSuccessMessage) {