Command read rework

This commit is contained in:
crschnick 2024-06-29 13:35:38 +00:00
parent f6c06b38c3
commit e6b6d9b325
2 changed files with 6 additions and 4 deletions

View file

@ -18,8 +18,10 @@ public class ShellExecExchangeImpl extends ShellExecExchange {
AtomicReference<String> err = new AtomicReference<>(); AtomicReference<String> err = new AtomicReference<>();
long exitCode; long exitCode;
try (var command = existing.getControl().command(msg.getCommand()).start()) { try (var command = existing.getControl().command(msg.getCommand()).start()) {
command.accumulateStdout(s -> out.set(s)); var r = command.readStdoutAndStderr();
command.accumulateStderr(s -> err.set(s)); out.set(r[0]);
err.set(r[1]);
command.close();
exitCode = command.getExitCode(); exitCode = command.getExitCode();
} }
return Response.builder() return Response.builder()

View file

@ -69,9 +69,9 @@ public interface CommandControl extends ProcessControl {
void withStdoutOrThrow(FailableConsumer<InputStreamReader, Exception> c); void withStdoutOrThrow(FailableConsumer<InputStreamReader, Exception> c);
String readStdoutDiscardErr() throws Exception; String[] readStdoutAndStderr() throws Exception;
String readJoinedOutputOrThrow() throws Exception; String readStdoutDiscardErr() throws Exception;
String readStderrDiscardStdout() throws Exception; String readStderrDiscardStdout() throws Exception;