Package com.norconex.commons.lang.exec
Class ExecUtil
java.lang.Object
com.norconex.commons.lang.exec.ExecUtil
Utility methods related to process execution. Checked exceptions
are wrapped in a runtime
ExecException.- Since:
- 1.13.0 (previously part of now deprecated JEF API)
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic intwatchProcess(Process process) Watches a running process.static intwatchProcess(Process process, InputStreamListener listener) Watches a running process.static intwatchProcess(Process process, InputStreamListener[] listeners) Watches a running process.static intwatchProcess(Process process, InputStreamListener[] outputListeners, InputStreamListener[] errorListeners) Watches a running process.static intwatchProcess(Process process, InputStreamListener outputListener, InputStreamListener errorListener) Watches a running process.static intwatchProcess(Process process, InputStream input, InputStreamListener[] outputListeners, InputStreamListener[] errorListeners) Watches a running process while sending data to its STDIN.static voidwatchProcessAsync(Process process, InputStreamListener[] outputListeners, InputStreamListener[] errorListeners) Watches process output.static voidwatchProcessAsync(Process process, InputStreamListener outputListener, InputStreamListener errorListener) Watches process output.static voidwatchProcessAsync(Process process, InputStream input, InputStreamListener[] outputListeners, InputStreamListener[] errorListeners) Watches process output while sending data to its STDIN.
-
Field Details
-
STDOUT
Identifier for standard output.- See Also:
-
STDERR
Identifier for standard error.- See Also:
-
-
Method Details
-
watchProcess
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
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
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, InputStreamListener outputListener, InputStreamListener errorListener) 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
-
watchProcess
public static int watchProcess(Process process, InputStreamListener[] outputListeners, InputStreamListener[] 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, InputStreamListener[] outputListeners, InputStreamListener[] 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, InputStreamListener outputListener, InputStreamListener errorListener) Watches process output. This method is the same aswatchProcess(Process, InputStreamListener, InputStreamListener)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, InputStreamListener[] outputListeners, InputStreamListener[] errorListeners) Watches process output. This method is the same aswatchProcess(Process, InputStreamListener[], InputStreamListener[])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, InputStreamListener[] outputListeners, InputStreamListener[] errorListeners) Watches process output while sending data to its STDIN. This method is the same aswatchProcess(Process, InputStream, InputStreamListener[], InputStreamListener[])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
-