Skip to content

Commit

Permalink
SystemRegistry: use terminal to flush and close streams in output red…
Browse files Browse the repository at this point in the history
…irection
  • Loading branch information
mattirn committed Oct 7, 2020
1 parent 12dbfa4 commit 43178f5
Showing 1 changed file with 7 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ private static class CommandOutputStream {
private ByteArrayOutputStream byteOutputStream;
private FileOutputStream fileOutputStream;
private PrintStream out;
private InputStream in;
private Terminal terminal;
private String output;
private CommandRegistry.CommandSession commandSession;
Expand Down Expand Up @@ -471,7 +470,7 @@ public void open() throws IOException {
System.setOut(out);
System.setErr(out);
String input = ctrl('X') + "q";
in = new ByteArrayInputStream( input.getBytes() );
InputStream in = new ByteArrayInputStream(input.getBytes());
Attributes attrs = new Attributes();
if (OSUtils.IS_WINDOWS) {
attrs.setInputFlag(InputFlag.IGNCR, true);
Expand All @@ -487,19 +486,9 @@ public void open() throws IOException {
}

public void flush() {
if (out == null) {
return;
}
try {
out.flush();
if (byteOutputStream != null) {
byteOutputStream.flush();
output = byteOutputStream.toString();
} else if (fileOutputStream != null) {
fileOutputStream.flush();
}
} catch (Exception e) {
// ignore
terminal.flush();
if (byteOutputStream != null) {
output = byteOutputStream.toString();
}
}

Expand All @@ -508,16 +497,10 @@ public void close() {
return;
}
try {
in.close();
flush();
if (byteOutputStream != null) {
byteOutputStream.close();
byteOutputStream = null;
} else if (fileOutputStream != null) {
fileOutputStream.close();
fileOutputStream = null;
}
out.close();
terminal.close();
byteOutputStream = null;
fileOutputStream = null;
out = null;
} catch (Exception e) {
// ignore
Expand Down

0 comments on commit 43178f5

Please sign in to comment.