From 57ba6a40b6c7f78b98613cd7748c5165ed6e887a Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 14 Jan 2014 17:44:29 +0000 Subject: [PATCH] Divert out/err streams while command runs Actually System.in works fine, it's the output streams that get buffered. We can fix it by diverting them for the duration of the command. Fixes gh-217 --- .../boot/cli/command/ShellCommand.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/ShellCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/ShellCommand.java index 916ccacff5..fe112f67a5 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/ShellCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/ShellCommand.java @@ -159,7 +159,7 @@ public class ShellCommand extends AbstractCommand { launchProcess(args, systemOut, systemErr); } else { - runCommand(args); + runCommand(args, systemOut, systemErr); } } } @@ -238,9 +238,20 @@ public class ShellCommand extends AbstractCommand { ReflectionUtils.invokeMethod(PROCESS_BUILDER_INHERIT_IO_METHOD, processBuilder); } - private void runCommand(List args) { + private void runCommand(List args, PrintStream systemOut, + PrintStream systemErr) { if (!getName().equals(args.get(0))) { - this.springCli.runAndHandleErrors(args.toArray(new String[args.size()])); + PrintStream out = System.out; + PrintStream err = System.err; + System.setOut(systemOut); + System.setErr(systemErr); + try { + this.springCli.runAndHandleErrors(args.toArray(new String[args.size()])); + } + finally { + System.setOut(out); + System.setErr(err); + } } }