diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ddba046..4ed1f68e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ### 0.2.16-SNAPSHOT (TBD) +### Features +* Added `setPrintToConsole` method to CommandRunner class in the `jpro-internal-util` module. This method can be used + to set the print output of the command runner to the console. This is useful for debugging purposes. ---------------------- diff --git a/internal/util/src/main/java/one/jpro/platform/internal/util/CommandRunner.java b/internal/util/src/main/java/one/jpro/platform/internal/util/CommandRunner.java index 33a20736..a133e3be 100644 --- a/internal/util/src/main/java/one/jpro/platform/internal/util/CommandRunner.java +++ b/internal/util/src/main/java/one/jpro/platform/internal/util/CommandRunner.java @@ -21,6 +21,7 @@ public class CommandRunner { private final List secretArgs = new ArrayList<>(); private final StringBuffer processOutput = new StringBuffer(); private boolean interactive = false; + private boolean printToConsole = false; /** * Initializes CommandRunner with default logger and command line arguments. @@ -52,6 +53,16 @@ public void setInteractive(boolean interactive) { this.interactive = interactive; } + /** + * When set to true, it will enable the process output to be + * printed to the console. By default, is false + * + * @param printToConsole a boolean that sets the print to console mode + */ + public void setPrintToConsole(boolean printToConsole) { + this.printToConsole = printToConsole; + } + /** * Adds a command line argument to the list of existing list of * command line arguments @@ -261,6 +272,9 @@ private Thread mergeProcessOutput(final InputStream inputStream) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { reader.lines().forEach(line -> { processOutput.append(line).append("\n"); + if (printToConsole) { + System.out.println(line); + } logger.debug(line); }); } catch (IOException ex) {