Package jnr.process

Class ProcessBuilder

java.lang.Object
jnr.process.ProcessBuilder

public class ProcessBuilder extends Object
ProcessBuilder mimics the API of the JDK ProcessBuilder class, providing methods to build up and launch a child process.
  • Field Details

    • command

      private List<String> command
    • env

      private Map<String,String> env
    • posix

      private static final jnr.posix.POSIX posix
  • Constructor Details

    • ProcessBuilder

      public ProcessBuilder(List<String> command)
      Create a new ProcessBuilder instance with the given command line.
      Parameters:
      command - the command line as a list of string arguments
    • ProcessBuilder

      public ProcessBuilder(String... command)
      Create a new ProcessBuilder instance with the given command line.
      Parameters:
      command - the command line as a varargs array of string arguments
  • Method Details

    • command

      public List<String> command()
      Get a copy of the list of command line arguments that will be used to launch the child process.
      Returns:
      a copied list of command line arguments
    • command

      public ProcessBuilder command(List<String> command)
      Replace the command line with the given list of command line arguments.
      Parameters:
      command - the new list of command line arguments
      Returns:
      this ProcessBuilder instance
    • command

      public ProcessBuilder command(String... command)
      Replace the command line with the given varargs array of command line arguments.
      Parameters:
      command - the new array of command line arguments
      Returns:
      this ProcessBuilder instance
    • environment

      public 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 operators.

      Returns:
      The process builder's environment.
    • start

      public Process start()
      Launch the subprocess and return a new Process instance.
      Returns:
      a new Process wrapping the child process's pid and IO streams