Interface ProcessAgent.ProcessBuilder

Enclosing interface:
ProcessAgent

public static interface ProcessAgent.ProcessBuilder
Each ProcessBuilder instance manages a collection of process attributes. The start() method creates a new Process instance with those attributes. The start() method can be invoked repeatedly from the same instance to create new subprocesses with identical or related attributes.
Since:
5.0.5
  • Method Details

    • command

      List<String> command()
      Returns this process builder's operating system program and arguments. The returned list is not a copy. Subsequent updates to the list will be reflected in the state of this process builder.
      Returns:
      This process builder's program and its arguments
      Since:
      5.0.5
    • command

      Sets this process builder's operating system program and arguments. This method does not make a copy of the command list. Subsequent updates to the list will be reflected in the state of the process builder. It is not checked whether command corresponds to a valid operating system command.
      Returns:
      This process builder
      Since:
      5.0.5
    • command

      ProcessAgent.ProcessBuilder command(String... command)
      Sets this process builder's operating system program and arguments. This is a convenience method that sets the command to a string list containing the same strings as the command array, in the same order. It is not checked whether command corresponds to a valid operating system command.
      Parameters:
      command - A string array containing the program and its arguments
      Returns:
      This process builder
      Since:
      5.0.5
    • environment

      Map<String,String> environment()
      Returns a string map view of this process builder's environment. Whenever a process builder is created, the environment is initialized to a copy of the current process environment (see System.getenv(). Subprocesses subsequently started by this object's start() method will use this map as their environment.

      The returned object may be modified using ordinary Map operations. These modifications will be visible to subprocesses started via the start() method. Two ProcessBuilder instances always contain independent process environments, so changes to the returned map will never be reflected in any other ProcessBuilder instance or the values returned by System.getenv().

      If the system does not support environment variables, an empty map is returned.

      Since:
      5.0.5
    • env

      Sets the specified name-value-pair to the environment().
      Returns:
      This process builder
      Since:
      5.0.5
    • redirectOutput

      ProcessAgent.ProcessBuilder redirectOutput(@Nullable @Nullable String prefix)
      Redirects error and normal output to the log.

      When redirected, the methods getInputStream() and getErrorStream() of the process instance provided by start() are no longer supported and will throw an IllegalStateException.

      Parameters:
      prefix - Prefix to use for redirected log messages.
      Returns:
      This process builder
      Since:
      5.0.5
    • start

      Process start() throws IOException
      Spawn a new process with the current configuration. The new process will invoke the command and arguments given by command(), with a process environment as given by environment().

      Starting an operating system process is highly system-dependent. Among the many things that can go wrong are:

      • The operating system program file was not found.
      • Access to the program file was denied.
      In such cases an exception will be thrown. The exact nature of the exception is system-dependent, but it will always be a subclass of IOException.

      Subsequent modifications to this process builder will not affect the returned Process.

      Throws:
      NullPointerException - If an element of the command list is null
      IndexOutOfBoundsException - If the command is an empty list (has size 0)
      SecurityException - If a security manager exists and its checkExec method doesn't allow creation of the subprocess
      IOException - If an I/O error occurs
      Since:
      5.0.5