Class ProcessManager

java.lang.Object
com.sun.enterprise.universal.process.ProcessManager

public final class ProcessManager extends Object
Extension of ProcessBuilder that provides additional functionality to manage input and output of the process.
Author:
bnevins 2005, Ondro Mihalyi, David Matejcek
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new ProcessManager with the specified command line.
    Creates a new ProcessManager with the specified command line.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Executes the command and waits for it to finish while reading its output.
    Returns the standard error output of the process.
    Returns the standard output of the process.
    void
    setEcho(boolean newEcho)
    Should the output of the process be echoed to stdout?
    void
    Sets an environment variable for the process.
    void
    Sets the input lines for the process.
    void
    setTextToWaitFor(String textToWaitFor)
    If not null, should wait until this text is found in standard output instead of waiting until the process terminates
    void
    setTimeout(int millis)
    Sets the timeout for the process execution or for the detected text in the output.
    void
    setTimeout(int millis, boolean forceExit)
    Sets the timeout for the process execution or for the detected text in the output.
    void
    setWorkingDir(File directory)
    Sets the working directory for the process.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ProcessManager

      public ProcessManager(String... cmds)
      Creates a new ProcessManager with the specified command line.
      Parameters:
      cmds - must not be null or empty.
    • ProcessManager

      public ProcessManager(List<String> cmdline)
      Creates a new ProcessManager with the specified command line.
      Parameters:
      cmdline - must not be null or empty.
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setTimeout

      public void setTimeout(int millis)
      Sets the timeout for the process execution or for the detected text in the output. If the process does not finish within the specified timeout, it will be terminated.
      Parameters:
      millis - the timeout in milliseconds, must not be negative
    • setTimeout

      public void setTimeout(int millis, boolean forceExit)
      Sets the timeout for the process execution or for the detected text in the output. If the process does not finish within the specified timeout, it can be terminated automatically.
      Parameters:
      millis - the timeout in milliseconds, must not be negative
      forceExit - if true, the process will be forcibly terminated if it does not finish within the timeout
    • setEnvironment

      public void setEnvironment(String name, String value)
      Sets an environment variable for the process.
      Parameters:
      name - the name of the environment variable, must not be null
      value - the value of the environment variable, can be null
    • setWorkingDir

      public void setWorkingDir(File directory)
      Sets the working directory for the process.
      Parameters:
      directory - the working directory, must not be null
    • setStdinLines

      public void setStdinLines(List<String> list)
      Sets the input lines for the process. The lines will be written to the process's standard input.
      Parameters:
      list - a list of strings to be written to the process's standard input, can be null or empty
    • setEcho

      public void setEcho(boolean newEcho)
      Should the output of the process be echoed to stdout?
      Parameters:
      newEcho -
    • setTextToWaitFor

      public void setTextToWaitFor(String textToWaitFor)
      If not null, should wait until this text is found in standard output instead of waiting until the process terminates
      Parameters:
      textToWaitFor -
    • getStdout

      public String getStdout()
      Returns the standard output of the process. If the textToWaitFor was set, the output will contain all lines read from the process until the textToWaitFor was found.
      Returns:
      the standard output of the process
    • getStderr

      public String getStderr()
      Returns the standard error output of the process. If the textToWaitFor was set, the output will contain all lines read from the process until the textToWaitFor was found.
      Returns:
      the standard error output of the process
    • execute

      public int execute() throws ProcessManagerException
      Executes the command and waits for it to finish while reading its output.
      Returns:
      exit code. Can be overridden internally when we are waiting for a specific text in output and we succeeded despite the process failed or even did not finish. If we have found the output, we don't kill the process.
      Throws:
      ProcessManagerException