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 runtime ExecException.
Since:
1.13.0 (previously part of now deprecated JEF API)
  • Field Details

  • Method Details

    • 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 the InputStreamConsumer to read its error and output stream.
      Parameters:
      process - the process to watch
      Returns:
      process exit value
    • watchProcess

      public static int watchProcess(Process process, InputStreamListener 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 the InputStreamConsumer 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
    • watchProcess

      public static int watchProcess(Process process, InputStreamListener[] 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 the InputStreamConsumer 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
    • 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 the InputStreamConsumer 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
    • 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 the InputStreamConsumer 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
    • 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 the InputStreamConsumer 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
      input - input sent to process STDIN
      outputListeners - the process output listeners
      errorListeners - 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 as watchProcess(Process, InputStreamListener, InputStreamListener) 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
    • watchProcessAsync

      public static void watchProcessAsync(Process process, InputStreamListener[] outputListeners, InputStreamListener[] errorListeners)
      Watches process output. This method is the same as watchProcess(Process, InputStreamListener[], InputStreamListener[]) 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
    • 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 as watchProcess(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 outputs
      input - input sent to process STDIN
      outputListeners - the process output listeners
      errorListeners - the process error listeners