com.github.maven_nar.cpptasks.compiler
Class CaptureStreamHandler

java.lang.Object
  extended by com.github.maven_nar.cpptasks.compiler.CaptureStreamHandler
All Implemented Interfaces:
org.apache.tools.ant.taskdefs.ExecuteStreamHandler

public class CaptureStreamHandler
extends Object
implements org.apache.tools.ant.taskdefs.ExecuteStreamHandler

Implements ExecuteStreamHandler to capture the output of a Execute to an array of strings

Author:
Curt Arnold

Constructor Summary
CaptureStreamHandler()
           
 
Method Summary
static CaptureStreamHandler execute(String[] cmdline)
          Executes the given command, capturing the output using a newly allocated CaptureStreamHandler, which is then returned.
 void gatherOutput()
          Reads concurrently both the process standard output and standard error.
 String[] getOutput()
          Gets the output of the execution.
 String[] getStderr()
          Gets the output of the execution's standard error stream.
 String[] getStdout()
          Gets the output of the execution's standard output stream.
static String[] run(String[] cmdline)
          Runs an executable and captures the output in a String array
 void setProcessErrorStream(InputStream is)
          Install a handler for the error stream of the subprocess.
 void setProcessInputStream(OutputStream os)
          Install a handler for the input stream of the subprocess.
 void setProcessOutputStream(InputStream is)
          Install a handler for the output stream of the subprocess.
 void start()
          Start handling of the streams.
 void stop()
          Stop handling of the streams - will not be restarted.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CaptureStreamHandler

public CaptureStreamHandler()
Method Detail

run

public static String[] run(String[] cmdline)
Runs an executable and captures the output in a String array

Parameters:
cmdline - command line arguments
Returns:
output of process
See Also:
getOutput()

execute

public static CaptureStreamHandler execute(String[] cmdline)
Executes the given command, capturing the output using a newly allocated CaptureStreamHandler, which is then returned.

In contrast to run(String[]), this method allows both the standard error and standard output streams to be inspected after execution (via the getStderr() and getStdout() methods, respectively).

Parameters:
cmdline - command line arguments
Returns:
The CaptureStreamHandler used to capture the output.

getOutput

public String[] getOutput()
Gets the output of the execution. If standard error is not empty, it is returned; otherwise, standard output is returned.


getStderr

public String[] getStderr()
Gets the output of the execution's standard error stream.


getStdout

public String[] getStdout()
Gets the output of the execution's standard output stream.


gatherOutput

public void gatherOutput()
Reads concurrently both the process standard output and standard error. The standard error is copied to the stderr string array field. The standard output is copied to the stdout string array field. Both fields are set to an empty array in case of any error.


setProcessErrorStream

public void setProcessErrorStream(InputStream is)
                           throws IOException
Install a handler for the error stream of the subprocess.

Specified by:
setProcessErrorStream in interface org.apache.tools.ant.taskdefs.ExecuteStreamHandler
Parameters:
is - input stream to read from the error stream from the subprocess
Throws:
IOException

setProcessInputStream

public void setProcessInputStream(OutputStream os)
                           throws IOException
Install a handler for the input stream of the subprocess.

Specified by:
setProcessInputStream in interface org.apache.tools.ant.taskdefs.ExecuteStreamHandler
Parameters:
os - output stream to write to the standard input stream of the subprocess
Throws:
IOException

setProcessOutputStream

public void setProcessOutputStream(InputStream is)
                            throws IOException
Install a handler for the output stream of the subprocess.

Specified by:
setProcessOutputStream in interface org.apache.tools.ant.taskdefs.ExecuteStreamHandler
Parameters:
is - input stream to read from the error stream from the subprocess
Throws:
IOException

start

public void start()
           throws IOException
Start handling of the streams.

Specified by:
start in interface org.apache.tools.ant.taskdefs.ExecuteStreamHandler
Throws:
IOException

stop

public void stop()
Stop handling of the streams - will not be restarted.

Specified by:
stop in interface org.apache.tools.ant.taskdefs.ExecuteStreamHandler


Copyright © 2002-2013 The Apache Software Foundation. All Rights Reserved.