JAL-629 Move more stdout messages to stderr when outputting file to stdout
[jalview.git] / src / jalview / bin / Launcher.java
index a87d322..6e820fd 100644 (file)
@@ -127,11 +127,13 @@ public class Launcher
     boolean debug = false;
     boolean wait = true;
     boolean quiet = false;
+    boolean stdout = false;
     // must set --debug before --launcher...
     boolean launcherstop = false;
     boolean launcherprint = false;
     boolean launcherwait = false;
     ArrayList<String> arguments = new ArrayList<>();
+    String previousArg = null;
     for (String arg : args)
     {
       if (arg.equals("--debug"))
@@ -142,6 +144,11 @@ public class Launcher
       {
         quiet = true;
       }
+      if (arg.equals("--output=-")
+              || (arg.equals("-") && "--output".equals(previousArg)))
+      {
+        stdout = true;
+      }
       if (debug && arg.equals("--launcherprint"))
       {
         launcherprint = true;
@@ -159,6 +166,7 @@ public class Launcher
       {
         wait = false;
       }
+      previousArg = arg;
       // Don't add the --launcher... args to Jalview launch
       if (arg.startsWith("--launcher"))
       {
@@ -280,7 +288,7 @@ public class Launcher
     String scalePropertyArg = HiDPISetting.getScalePropertyArg();
     if (scalePropertyArg != null)
     {
-      sysout(debug, quiet, "Running " + startClass + " with scale setting "
+      syserr(debug, quiet, "Running " + startClass + " with scale setting "
               + scalePropertyArg);
       command.add(scalePropertyArg);
     }
@@ -293,10 +301,10 @@ public class Launcher
     if ((Boolean.parseBoolean(System.getProperty("launcherprint", "false"))
             || launcherprint))
     {
-      sysout(debug, quiet,
+      syserr(debug, quiet,
               "LAUNCHER COMMAND: " + String.join(" ", builder.command()));
     }
-    sysout(debug, quiet,
+    syserr(debug, quiet,
             "Running " + startClass + " with "
                     + (memSetting == null ? "no memory setting"
                             : ("memory setting " + memSetting)));
@@ -304,7 +312,7 @@ public class Launcher
     if (Boolean.parseBoolean(System.getProperty("launcherstop", "false"))
             || (debug && launcherstop))
     {
-      sysout(debug, quiet,
+      syserr(debug, quiet,
               "System property 'launcherstop' is set and not 'false'. Exiting.");
       System.exit(0);
     }
@@ -314,17 +322,17 @@ public class Launcher
       Process process = builder.start();
       if (wait || launcherwait)
       {
-        sysout(debug, quiet, "Launching application process");
+        syserr(debug, quiet, "Launching application process");
         process.waitFor();
       }
       else
       {
         int waitInt = 0;
-        sysout(debug, quiet,
+        syserr(debug, quiet,
                 "Wait time for application process is " + waitInt + "ms");
         process.waitFor(waitInt, TimeUnit.MILLISECONDS);
       }
-      sysout(debug, quiet, "Launcher process ending");
+      syserr(debug, quiet, "Launcher process ending");
     } catch (IOException e)
     {
       if (e.getMessage().toLowerCase(Locale.ROOT).contains("memory"))
@@ -364,11 +372,11 @@ public class Launcher
     }
   }
 
-  private static void sysout(boolean debug, boolean quiet, String message)
+  private static void syserr(boolean debug, boolean quiet, String message)
   {
     if (debug && !quiet)
     {
-      System.out.println("LAUNCHERDEBUG - " + message);
+      System.err.println("LAUNCHERDEBUG - " + message);
     }
   }