Package org.apache.commons.exec

# Class DefaultExecuteResultHandler

java.lang.Object
org.apache.commons.exec.DefaultExecuteResultHandler

All Implemented Interfaces:
  `ExecuteResultHandler`

public class DefaultExecuteResultHandler extends Object implements ExecuteResultHandler
A default implementation of 'ExecuteResultHandler' used for asynchronous process handling.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DefaultExecuteResultHandler()`
  Constructs a new instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `ExecuteException`
  `getException()`
  Gets the `exception` causing the process execution to fail.
  `int`
  `getExitValue()`
  Gets the `exitValue` of the process.
  `boolean`
  `hasResult()`
  Tests whether the process exited and a result is available, i.e. exitCode or exception?
  `void`
  `onProcessComplete(int exitValue)`
  The asynchronous execution completed.
  `void`
  `onProcessFailed(ExecuteException e)`
  The asynchronous execution failed.
  `void`
  `waitFor()`
  Causes the current thread to wait, if necessary, until the process has terminated.
  `void`
  `waitFor(long timeoutMillis)`
  Deprecated.
  Use `waitFor(Duration)`.
  `void`
  `waitFor(Duration timeout)`
  Causes the current thread to wait, if necessary, until the process has terminated.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### DefaultExecuteResultHandler

    public DefaultExecuteResultHandler()
    Constructs a new instance.

- ## Method Details

  - ### getException

    public ExecuteException getException()
    Gets the `exception` causing the process execution to fail.
    Returns:
      the exception.
    Throws:
      `IllegalStateException` - if the process has not exited yet.

  - ### getExitValue

    public int getExitValue()
    Gets the `exitValue` of the process.
    Returns:
      the exitValue.
    Throws:
      `IllegalStateException` - if the process has not exited yet.

  - ### hasResult

    public boolean hasResult()
    Tests whether the process exited and a result is available, i.e. exitCode or exception?
    Returns:
      true whether a result of the execution is available.

  - ### onProcessComplete

    public void onProcessComplete(int exitValue)
    Description copied from interface: `ExecuteResultHandler`
    The asynchronous execution completed.
    Specified by:
      `onProcessComplete` in interface `ExecuteResultHandler`
    Parameters:
      `exitValue` - the exit value of the sub-process.
    See Also:
      - `ExecuteResultHandler.onProcessComplete(int)`

  - ### onProcessFailed

    public void onProcessFailed(ExecuteException e)
    Description copied from interface: `ExecuteResultHandler`
    The asynchronous execution failed.
    Specified by:
      `onProcessFailed` in interface `ExecuteResultHandler`
    Parameters:
      `e` - the `ExecuteException` containing the root cause.
    See Also:
      - `ExecuteResultHandler.onProcessFailed(org.apache.commons.exec.ExecuteException)`

  - ### waitFor

    public void waitFor() throws InterruptedException
    Causes the current thread to wait, if necessary, until the process has terminated. This method returns immediately if the process has already terminated. If the process has not yet terminated, the calling thread will be blocked until the process exits.
    Throws:
      `InterruptedException` - if the current thread is interrupted by another thread while it is waiting, then the wait is ended and an `InterruptedException` is thrown.

  - ### waitFor

    public void waitFor(Duration timeout) throws InterruptedException
    Causes the current thread to wait, if necessary, until the process has terminated. This method returns immediately if the process has already terminated. If the process has not yet terminated, the calling thread will be blocked until the process exits.
    Parameters:
      `timeout` - the maximum time to wait.
    Throws:
      `InterruptedException` - if the current thread is interrupted by another thread while it is waiting, then the wait is ended and an `InterruptedException` is thrown.
    Since:
      1.4.0

  - ### waitFor

    @Deprecated public void waitFor(long timeoutMillis) throws InterruptedException
    Deprecated.
    Use `waitFor(Duration)`.
    Causes the current thread to wait, if necessary, until the process has terminated. This method returns immediately if the process has already terminated. If the process has not yet terminated, the calling thread will be blocked until the process exits.
    Parameters:
      `timeoutMillis` - the maximum time to wait in milliseconds.
    Throws:
      `InterruptedException` - if the current thread is interrupted by another thread while it is waiting, then the wait is ended and an `InterruptedException` is thrown.