001    
002    package com.perdues.test;
003    
004    import java.io.*;
005    import java.util.logging.Logger;
006    import java.util.logging.Level;
007    import com.perdues.ProcessUtils;
008    
009    
010    public class ProcessUtilsTest {
011    
012      /**
013        Main routine that takes the name of the program to run and its
014        arguments are the command line arguments.  The system property
015        "style" controls which "exec" method of class
016        com.perdues.ProcessUtils this will invoke.  The permitted values
017        are "string", "write", or "filter".  These use respectively the
018        form of exec that: returns a string; writes to two output streams;
019        or reads an input stream and writes output streams.  The default
020        style is "string".
021        */
022      public static void main(String[] args) {
023        try {
024          String style = System.getProperty("style");
025          if ("write".equals(style)) {
026            StringWriter errs = new StringWriter();
027            ProcessUtils.exec(args, new InputStreamReader(System.in),
028              new OutputStreamWriter(System.out), errs);
029              System.out.println();
030              System.out.println("Error output:");
031              System.out.print(errs.toString());
032          } else if ("filter".equals(style)) {
033            System.out.println
034             ("Exit "+ProcessUtils.exec(args, System.in, System.out, System.err));
035          } else if ("string".equals(style) || style==null) {
036            System.out.print(ProcessUtils.exec(args));
037          } else {
038            System.out.println
039              ("Please specify a style of 'write', 'filter', or 'string'");
040            System.exit(1);
041          }
042        } catch(java.lang.Throwable ex) {
043          Logger.getLogger(ProcessUtilsTest.class.getName())
044            .log(Level.WARNING, null, ex);
045        }
046      }
047    
048    }