diff --git a/source/net/filebot/cli/PseudoConsole.java b/source/net/filebot/cli/PseudoConsole.java index 6bca04b1..8f09b23c 100644 --- a/source/net/filebot/cli/PseudoConsole.java +++ b/source/net/filebot/cli/PseudoConsole.java @@ -10,6 +10,7 @@ import java.io.PrintStream; import java.io.PrintWriter; import java.io.Reader; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; /** * A {@link Console} like class for when {@link System#console()} is not available in the current JVM @@ -18,6 +19,15 @@ import java.nio.charset.Charset; */ public class PseudoConsole { + private static PseudoConsole STDIO; + + public static synchronized PseudoConsole getSystemConsole() { + if (STDIO == null) { + STDIO = new PseudoConsole(System.in, System.out, StandardCharsets.UTF_8); + } + return STDIO; + } + private final BufferedReader reader; private final PrintWriter writer; diff --git a/source/net/filebot/cli/ScriptShellBaseClass.java b/source/net/filebot/cli/ScriptShellBaseClass.java index b3955668..9581d461 100644 --- a/source/net/filebot/cli/ScriptShellBaseClass.java +++ b/source/net/filebot/cli/ScriptShellBaseClass.java @@ -16,7 +16,6 @@ import java.io.InputStreamReader; import java.io.PrintStream; import java.io.StringWriter; import java.net.Socket; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Date; import java.util.EnumMap; @@ -190,7 +189,7 @@ public abstract class ScriptShellBaseClass extends Script { // define global variable: console public Object getConsole() { - return System.console() != null ? System.console() : new PseudoConsole(System.in, System.out, StandardCharsets.UTF_8); + return System.console() != null ? System.console() : PseudoConsole.getSystemConsole(); } public Date getNow() {