Class 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)
    Author:
    Pascal Essiembre
    • 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 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,
                                       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 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,
                                       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 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,
                                       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 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
        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 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,
                                       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 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