diff --git a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java index 24cec551a..07f360065 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java +++ b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java @@ -129,6 +129,9 @@ public ProcessContext withPathEntry(Path path) { @Override public ProcessResult run(ProcessMode processMode) { + final String ERROR_PREFIX = "ERROR: "; + final String OUTPUT_PREFIX = "OUTPUT: "; + if (processMode == ProcessMode.DEFAULT) { this.processBuilder.redirectOutput(Redirect.INHERIT).redirectError(Redirect.INHERIT); } @@ -167,16 +170,16 @@ public ProcessResult run(ProcessMode processMode) { this.processBuilder.command(args); - List out = null; + List logs = new ArrayList<>(); List err = null; Process process = this.processBuilder.start(); if (processMode == ProcessMode.DEFAULT_CAPTURE) { - CompletableFuture> outFut = readInputStream(process.getInputStream()); - CompletableFuture> errFut = readInputStream(process.getErrorStream()); - out = outFut.get(); - err = errFut.get(); + CompletableFuture> outFut = readInputStream(process.getInputStream(), false, logs); + CompletableFuture> errFut = readInputStream(process.getErrorStream(), true, logs); + outFut.get(); + errFut.get(); } int exitCode; @@ -187,10 +190,9 @@ public ProcessResult run(ProcessMode processMode) { exitCode = process.waitFor(); } - ProcessResult result = new ProcessResultImpl(exitCode, out, err); + ProcessResult result = new ProcessResultImpl(exitCode, logs, null); performLogging(result, exitCode, interpreter); - return result; } catch (CliProcessException | IllegalStateException e) { @@ -214,11 +216,19 @@ public ProcessResult run(ProcessMode processMode) { * @param is {@link InputStream}. * @return {@link CompletableFuture}. */ - private static CompletableFuture> readInputStream(InputStream is) { + private static CompletableFuture> readInputStream(InputStream is, boolean errorStream, List logs) { return CompletableFuture.supplyAsync(() -> { try (InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr)) { + + String prefix = errorStream ? "- " : "+ "; + String line; + while ((line = br.readLine()) != null) { + synchronized (logs) { + logs.add(prefix + line); + } + } return br.lines().toList(); } catch (Throwable e) { throw new RuntimeException("There was a problem while executing the program", e);