com.norconex.jef.exec
Class ExecUtils

java.lang.Object
  extended by com.norconex.jef.exec.ExecUtils

public final class ExecUtils
extends Object

Utility methods related to process execution.

Author:
Pascal Essiembre

Field Summary
static String STDERR
          Identifier for standard error.
static String STDOUT
          Identifier for standard output.
 
Method Summary
static int watchProcess(Process process)
          Watches a running process.
static int watchProcess(Process process, IStreamListener listener)
          Watches a running process.
static int watchProcess(Process process, IStreamListener[] listeners)
          Watches a running process.
static int watchProcess(Process process, IStreamListener[] outputListeners, IStreamListener[] errorListeners)
          Watches a running process.
static int watchProcess(Process process, IStreamListener outputListener, IStreamListener errorListener)
          Watches a running process.
static void watchProcessOutput(Process process, IStreamListener[] outputListeners, IStreamListener[] errorListeners)
          Watches process output.
static void watchProcessOutput(Process process, IStreamListener outputListener, IStreamListener errorListener)
          Watches process output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STDOUT

public static final String STDOUT
Identifier for standard output.

See Also:
Constant Field Values

STDERR

public static final String STDERR
Identifier for standard error.

See Also:
Constant Field Values
Method Detail

watchProcess

public static int watchProcess(Process process)
                        throws InterruptedException
Watches a running process. This method will wait until the process as finished executing before returning with its exit value. It ensures the process does not hang on some platform by making use of the StreamGobbler to read its error and output stream.

Parameters:
process - the process to watch
Returns:
process exit value
Throws:
InterruptedException - problem while waiting for process to finish

watchProcess

public static int watchProcess(Process process,
                               IStreamListener listener)
                        throws InterruptedException
Watches a running process. This method will wait until the process as finished executing before returning with its exit value. It ensures the process does not hang on some platform by making use of the StreamGobbler to read its error and output stream. The listener will be notified every time an error or output line gets written by the process. The listener line type will either be "STDERR" or "STDOUT".

Parameters:
process - the process to watch
listener - the listener to use for both "STDERR" or "STDOUT".
Returns:
process exit value
Throws:
InterruptedException - problem while waiting for process to finish

watchProcess

public static int watchProcess(Process process,
                               IStreamListener[] listeners)
                        throws InterruptedException
Watches a running process. This method will wait until the process as finished executing before returning with its exit value. It ensures the process does not hang on some platform by making use of the StreamGobbler to read its error and output stream. The listener will be notified every time an error or output line gets written by the process. The listener line type will either be "STDERR" or "STDOUT".

Parameters:
process - the process to watch
listeners - the listeners to use for both "STDERR" or "STDOUT".
Returns:
process exit value
Throws:
InterruptedException - problem while waiting for process to finish

watchProcess

public static int watchProcess(Process process,
                               IStreamListener outputListener,
                               IStreamListener errorListener)
                        throws InterruptedException
Watches a running process. This method will wait until the process as finished executing before returning with its exit value. It ensures the process does not hang on some platform by making use of the StreamGobbler to read its error and output stream. The listener will be notified every time an error or output line gets written by the process. The listener line type will either be "STDERR" or "STDOUT".

Parameters:
process - the process to watch
outputListener - the process output listener
errorListener - the process error listener
Returns:
process exit value
Throws:
InterruptedException - problem while waiting for process to finish

watchProcess

public static int watchProcess(Process process,
                               IStreamListener[] outputListeners,
                               IStreamListener[] errorListeners)
                        throws InterruptedException
Watches a running process. This method will wait until the process as finished executing before returning with its exit value. It ensures the process does not hang on some platform by making use of the StreamGobbler to read its error and output stream. The listeners will be notified every time an error or output line gets written by the process. The listener line type will either be "STDERR" or "STDOUT".

Parameters:
process - the process to watch
outputListeners - the process output listeners
errorListeners - the process error listeners
Returns:
process exit value
Throws:
InterruptedException - problem while waiting for process to finish

watchProcessOutput

public static void watchProcessOutput(Process process,
                                      IStreamListener outputListener,
                                      IStreamListener errorListener)
Watches process output. This method is the same as watchProcess(Process, IStreamListener, IStreamListener) with the exception of not waiting for the process to complete before returning.

Parameters:
process - the process on which to watch outputs
outputListener - the process output listeners
errorListener - the process error listeners
Since:
2.0

watchProcessOutput

public static void watchProcessOutput(Process process,
                                      IStreamListener[] outputListeners,
                                      IStreamListener[] errorListeners)
Watches process output. This method is the same as watchProcess(Process, IStreamListener[], IStreamListener[]) with the exception of not waiting for the process to complete before returning.

Parameters:
process - the process on which to watch outputs
outputListeners - the process output listeners
errorListeners - the process error listeners
Since:
2.0


Copyright © 2007-2013 Norconex Inc.. All Rights Reserved.