Class DefaultExecutor

java.lang.Object
org.apache.commons.exec.DefaultExecutor
All Implemented Interfaces:
Executor
Direct Known Subclasses:
DaemonExecutor

public class DefaultExecutor extends Object implements Executor
The default class to start a subprocess. The implementation allows to
  • set a current working directory for the subprocess
  • provide a set of environment variables passed to the subprocess
  • capture the subprocess output of stdout and stderr using an ExecuteStreamHandler
  • kill long-running processes using an ExecuteWatchdog
  • define a set of expected exit values
  • terminate any started processes when the main process is terminating using a ProcessDestroyer
The following example shows the basic usage:
 Executor exec = new DefaultExecutor();
 CommandLine cl = new CommandLine("ls -l");
 int exitvalue = exec.execute(cl);
 
Version:
$Id: DefaultExecutor.java 1636056 2014-11-01 21:12:52Z ggregory $
  • Field Details

    • streamHandler

      private ExecuteStreamHandler streamHandler
      taking care of output and error stream
    • workingDirectory

      private File workingDirectory
      the working directory of the process
    • watchdog

      private ExecuteWatchdog watchdog
      monitoring of long running processes
    • exitValues

      private int[] exitValues
      the exit values considered to be successful
    • launcher

      private final CommandLauncher launcher
      launches the command in a new process
    • processDestroyer

      private ProcessDestroyer processDestroyer
      optional cleanup of started processes
    • executorThread

      private Thread executorThread
      worker thread for asynchronous execution
    • exceptionCaught

      private IOException exceptionCaught
      the first exception being caught to be thrown to the caller
  • Constructor Details

    • DefaultExecutor

      public DefaultExecutor()
      Default constructor creating a default PumpStreamHandler and sets the working directory of the subprocess to the current working directory. The PumpStreamHandler pumps the output of the subprocess into our System.out and System.err to avoid into our System.out and System.err to avoid a blocked or deadlocked subprocess (seeProcess).
  • Method Details