Author: bfoster
Date: Fri Mar 16 06:47:58 2012
New Revision: 1301350

URL: http://svn.apache.org/viewvc?rev=1301350&view=rev
Log:
Add support to ExecUtils callProgram to take OutputStreams for forwarding 
stdout and stderr

-------------
OODT-415

Modified:
    oodt/trunk/commons/src/main/java/org/apache/oodt/commons/exec/ExecUtils.java

Modified: 
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/exec/ExecUtils.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/commons/src/main/java/org/apache/oodt/commons/exec/ExecUtils.java?rev=1301350&r1=1301349&r2=1301350&view=diff
==============================================================================
--- 
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/exec/ExecUtils.java 
(original)
+++ 
oodt/trunk/commons/src/main/java/org/apache/oodt/commons/exec/ExecUtils.java 
Fri Mar 16 06:47:58 2012
@@ -24,6 +24,7 @@ import org.apache.oodt.commons.io.Logger
 //JDK imports
 import java.io.File;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -57,11 +58,35 @@ public final class ExecUtils {
 
     public static int callProgram(String commandLine, Logger logger)
             throws IOException {
-        return callProgram(commandLine, logger, null);
+       try {
+          return callProgram(commandLine,
+                             new LoggerOutputStream(logger, Level.INFO),
+                             new LoggerOutputStream(logger, Level.SEVERE),
+                             null);
+       } catch (Exception e) {
+          throw new IOException(e);
+       }
+    }
+
+    public static int callProgram(String commandLine, OutputStream 
stdOutStream,
+          OutputStream stdErrStream) throws IOException {
+       return callProgram(commandLine, stdOutStream, stdErrStream, null);
     }
 
     public static int callProgram(String commandLine, Logger logger,
-            File workDir) throws IOException {
+          File workDir) throws IOException {
+       try {
+          return callProgram(commandLine,
+                             new LoggerOutputStream(logger, Level.INFO),
+                             new LoggerOutputStream(logger, Level.SEVERE),
+                             workDir);
+       } catch (Exception e) {
+          throw new IOException(e);
+       }
+    }
+
+    public static int callProgram(String commandLine, OutputStream 
stdOutStream,
+            OutputStream stdErrStream, File workDir) throws IOException {
         Process progProcess = null;
         StreamGobbler errorGobbler = null, outputGobbler = null;
         int returnVal = -1;
@@ -70,9 +95,9 @@ public final class ExecUtils {
                     commandLine) : Runtime.getRuntime().exec(commandLine, null,
                     workDir);
             errorGobbler = new StreamGobbler(progProcess.getErrorStream(),
-                    "ERROR", new LoggerOutputStream(logger, Level.SEVERE));
+                    "ERROR", stdErrStream);
             outputGobbler = new StreamGobbler(progProcess.getInputStream(),
-                    "OUTPUT", new LoggerOutputStream(logger, Level.INFO));
+                    "OUTPUT", stdOutStream);
             errorGobbler.start();
             outputGobbler.start();
             returnVal = progProcess.waitFor();


Reply via email to