[Webfunds-commits] java/webfunds/client Core.java

Jeroen C. van Gelderen gelderen@cypherpunks.ai
Sun, 4 Jun 2000 15:47:27 -0400 (AST)


gelderen    00/06/04 15:47:27

  Modified:    webfunds/client Core.java
  Log:
  Tee std{err|out} to both a file and std{err|out}.

Revision  Changes    Path
1.55      +41 -1     java/webfunds/client/Core.java

Index: Core.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/Core.java,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- Core.java	2000/06/01 01:07:16	1.54
+++ Core.java	2000/06/04 19:47:27	1.55
@@ -1,4 +1,4 @@
-/* $Id: Core.java,v 1.54 2000/06/01 01:07:16 gelderen Exp $
+/* $Id: Core.java,v 1.55 2000/06/04 19:47:27 gelderen Exp $
  *
  * Copyright (c) Systemics Inc. 1995-2000 on behalf of
  * The WebFunds Development Team.  All rights reserved.
@@ -12,6 +12,7 @@
 import java.util.*;
 
 import webfunds.utils.Debug;
+import webfunds.utils.MultiPrintStream;
 import webfunds.utils.NetWatcher;
 import webfunds.utils.SecureRandomHack;
 import webfunds.utils.VersionNumbers;
@@ -431,8 +432,47 @@
     }
 
 
+    /**
+     * Return a PrintStream for output to the given filename or null.
+     * Helper for redirectOutAndErr().
+     *
+     * @return PrintStream or null
+     */
+    private static PrintStream getPrintStreamForFile(String name)
+    {
+        try
+        {
+            return new PrintStream( new FileOutputStream(name) );
+        }
+        catch(IOException e)       { /*ignore*/ }
+        catch(SecurityException e) { /*ignore*/ }
+
+        return null;
+    }
+
+
+    /**
+     * Tee stdout and stderr.
+     */
+    private static void redirectOutAndErr()
+    {
+        PrintStream[] streams = new PrintStream[2];
+
+        streams[0] = System.out;
+        streams[1] = getPrintStreamForFile("./stdout");
+        System.setOut( new MultiPrintStream(streams) );
+
+        streams[0] = System.err;
+        streams[1] = getPrintStreamForFile("./stderr");
+        System.setErr( new MultiPrintStream(streams) );
+               
+    }
+
+
     public static void main(String[] arg)
     {
+        redirectOutAndErr();
+
         if (arg.length > 0)
         {
             if ("-help".equals(arg[0]) || "-?".equals(arg[0]))