Class SimpleProcess


  • public class SimpleProcess
    extends Object
    This is a convenient wrapper for ProcessBuilder and Process that simplifies starting a process, waiting for it to finish and getting its stdout.
    • Method Detail

      • start

        public static String start​(List<String> command,
                                   Duration executionTimeout)
        Starts a new process using the working directory of the current Java process and waits until it terminates successfully.
        Parameters:
        command - command to execute
        executionTimeout - execution timeout for the process
        Returns:
        combined stdout and stderr from the process
      • start

        public static String start​(Path workingDirectory,
                                   List<String> command,
                                   Duration executionTimeout)
        Starts a new process using the given working directory and waits until it terminates successfully.
        Parameters:
        workingDirectory - directory in which to start the process. Use the working directory of the current Java process if null.
        command - command to execute
        executionTimeout - execution timeout for the process
        Returns:
        combined stdout and stderr from the process
      • waitUntilTerminatedSuccessfully

        public void waitUntilTerminatedSuccessfully​(Duration executionTimeout)
        Wait for the process to terminate successfully.
        Parameters:
        executionTimeout - maximum time to wait until the process finishes
        Throws:
        IllegalStateException - if the process did not finish within the given timeout or returned an exit code other than 0
      • stop

        public void stop()
        Destroy a running process.