Skip to content

Commit 439676e

Browse files
czpilarfmbenhassine
authored andcommitted
Fix discarded output of commands executed from within a script
Resolve #1270 Signed-off-by: czpilar <david@czpilar.net>
1 parent ad3b96c commit 439676e

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

spring-shell-core/src/main/java/org/springframework/shell/core/NonInteractiveShellRunner.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class NonInteractiveShellRunner implements ShellRunner {
4949
private final CommandRegistry commandRegistry;
5050

5151
// Use a no-op PrintWriter since output is not needed in non-interactive mode
52-
private final PrintWriter outputWriter = new PrintWriter(PrintWriter.nullWriter());
52+
private PrintWriter outputWriter = new PrintWriter(PrintWriter.nullWriter());
5353

5454
// Use a no-op InputReader since input is not needed in non-interactive mode
5555
private final InputReader inputReader = new InputReader() {
@@ -66,6 +66,19 @@ public NonInteractiveShellRunner(CommandParser commandParser, CommandRegistry co
6666
this.commandExecutor = new CommandExecutor(commandRegistry);
6767
}
6868

69+
/**
70+
* Create a new {@link NonInteractiveShellRunner} instance.
71+
* @param commandParser the command parser
72+
* @param commandRegistry the command registry
73+
* @param outputWriter the output writer
74+
* @since 4.0.1
75+
*/
76+
public NonInteractiveShellRunner(CommandParser commandParser, CommandRegistry commandRegistry,
77+
PrintWriter outputWriter) {
78+
this(commandParser, commandRegistry);
79+
this.outputWriter = outputWriter;
80+
}
81+
6982
@Override
7083
public void run(String[] args) throws Exception {
7184
if (ObjectUtils.isEmpty(args)) {

spring-shell-core/src/main/java/org/springframework/shell/core/command/Script.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public ExitStatus execute(CommandContext commandContext) throws Exception {
6363
private void executeCommand(CommandContext commandContext, String input) throws Exception {
6464
String[] commandTokens = input.split(" ");
6565
NonInteractiveShellRunner shellRunner = new NonInteractiveShellRunner(this.commandParser,
66-
commandContext.commandRegistry());
66+
commandContext.commandRegistry(), commandContext.outputWriter());
6767
shellRunner.run(commandTokens);
6868
}
6969

0 commit comments

Comments
 (0)