Package com.norconex.commons.lang.exec
Class ExecUtil
- java.lang.Object
-
- com.norconex.commons.lang.exec.ExecUtil
-
public final class ExecUtil extends Object
Utility methods related to process execution. Checked exceptions are wrapped in a runtimeExecException.- Since:
- 1.13.0 (previously part of now deprecated JEF API)
- Author:
- Pascal Essiembre
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intwatchProcess(Process process)Watches a running process.static intwatchProcess(Process process, IInputStreamListener listener)Watches a running process.static intwatchProcess(Process process, IInputStreamListener[] listeners)Watches a running process.static intwatchProcess(Process process, IInputStreamListener[] outputListeners, IInputStreamListener[] errorListeners)Watches a running process.static intwatchProcess(Process process, IInputStreamListener outputListener, IInputStreamListener errorListener)Watches a running process.static intwatchProcess(Process process, InputStream input, IInputStreamListener[] outputListeners, IInputStreamListener[] errorListeners)Watches a running process while sending data to its STDIN.static voidwatchProcessAsync(Process process, IInputStreamListener[] outputListeners, IInputStreamListener[] errorListeners)Watches process output.static voidwatchProcessAsync(Process process, IInputStreamListener outputListener, IInputStreamListener errorListener)Watches process output.static voidwatchProcessAsync(Process process, InputStream input, IInputStreamListener[] outputListeners, IInputStreamListener[] errorListeners)Watches process output while sending data to its STDIN.
-
-
-
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)
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 theInputStreamConsumerto read its error and output stream.- Parameters:
process- the process to watch- Returns:
- process exit value
-
watchProcess
public static int watchProcess(Process process, IInputStreamListener listener)
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 theInputStreamConsumerto 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 watchlistener- the listener to use for both "STDERR" or "STDOUT".- Returns:
- process exit value
-
watchProcess
public static int watchProcess(Process process, IInputStreamListener[] listeners)
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 theInputStreamConsumerto 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 watchlisteners- the listeners to use for both "STDERR" or "STDOUT".- Returns:
- process exit value
-
watchProcess
public static int watchProcess(Process process, IInputStreamListener outputListener, IInputStreamListener 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 theInputStreamConsumerto 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 watchoutputListener- the process output listenererrorListener- the process error listener- Returns:
- process exit value
- Throws:
InterruptedException- problem while waiting for process to finish
-
watchProcess
public static int watchProcess(Process process, IInputStreamListener[] outputListeners, IInputStreamListener[] errorListeners)
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 theInputStreamConsumerto 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 watchoutputListeners- the process output listenerserrorListeners- the process error listeners- Returns:
- process exit value
-
watchProcess
public static int watchProcess(Process process, InputStream input, IInputStreamListener[] outputListeners, IInputStreamListener[] errorListeners)
Watches a running process while sending data to its STDIN. 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 theInputStreamConsumerto 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 watchinput- input sent to process STDINoutputListeners- the process output listenerserrorListeners- the process error listeners- Returns:
- process exit value
-
watchProcessAsync
public static void watchProcessAsync(Process process, IInputStreamListener outputListener, IInputStreamListener errorListener)
Watches process output. This method is the same aswatchProcess( Process, IInputStreamListener, IInputStreamListener)with the exception of not waiting for the process to complete before returning.- Parameters:
process- the process on which to watch outputsoutputListener- the process output listenerserrorListener- the process error listeners
-
watchProcessAsync
public static void watchProcessAsync(Process process, IInputStreamListener[] outputListeners, IInputStreamListener[] errorListeners)
Watches process output. This method is the same aswatchProcess( Process, IInputStreamListener[], IInputStreamListener[])with the exception of not waiting for the process to complete before returning.- Parameters:
process- the process on which to watch outputsoutputListeners- the process output listenerserrorListeners- the process error listeners
-
watchProcessAsync
public static void watchProcessAsync(Process process, InputStream input, IInputStreamListener[] outputListeners, IInputStreamListener[] errorListeners)
Watches process output while sending data to its STDIN. This method is the same aswatchProcess(Process, InputStream, IInputStreamListener[], IInputStreamListener[])with the exception of not waiting for the process to complete before returning.- Parameters:
process- the process on which to watch outputsinput- input sent to process STDINoutputListeners- the process output listenerserrorListeners- the process error listeners
-
-