Package jnr.process

Class ProcessBuilder


  • public class ProcessBuilder
    extends java.lang.Object
    ProcessBuilder mimics the API of the JDK ProcessBuilder class, providing methods to build up and launch a child process.
    • Constructor Summary

      Constructors 
      Constructor Description
      ProcessBuilder​(java.lang.String... command)
      Create a new ProcessBuilder instance with the given command line.
      ProcessBuilder​(java.util.List<java.lang.String> command)
      Create a new ProcessBuilder instance with the given command line.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<java.lang.String> command()
      Get a copy of the list of command line arguments that will be used to launch the child process.
      ProcessBuilder command​(java.lang.String... command)
      Replace the command line with the given varargs array of command line arguments.
      ProcessBuilder command​(java.util.List<java.lang.String> command)
      Replace the command line with the given list of command line arguments.
      java.util.Map<java.lang.String,​java.lang.String> environment()
      Returns a string map view of this process builder's environment.
      Process start()
      Launch the subprocess and return a new Process instance.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ProcessBuilder

        public ProcessBuilder​(java.util.List<java.lang.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​(java.lang.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 Detail

      • command

        public java.util.List<java.lang.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​(java.util.List<java.lang.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​(java.lang.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 java.util.Map<java.lang.String,​java.lang.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