From 65e88be2b6dadee48f4eb2b5ca6ff36b1f2dbe9b Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 19 Apr 2015 04:36:29 +0000 Subject: [PATCH] * fix IO redirection issues when script is reading from STDIN --- source/net/filebot/cli/PseudoConsole.java | 10 ++++++++++ source/net/filebot/cli/ScriptShellBaseClass.java | 3 +-- 2 files changed, 11 insertions(+), 2 deletions(-) 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() {