Interface ProcessExecutor


  • public interface ProcessExecutor
    A helper class for launching an external process and handling its output.
    Author:
    Fabrizio Giudici
    • Method Detail

      • forExecutable

        @Nonnull
        static ProcessExecutor forExecutable​(@Nonnull
                                             java.lang.String executable)
                                      throws java.io.IOException
        Specifies the executable to run. It is searched in the path.
        Parameters:
        executable - the executable
        Returns:
        itself
        Throws:
        java.io.IOException - if something goes wrong
      • withArgument

        @Nonnull
        ProcessExecutor withArgument​(@Nonnull
                                     java.lang.String argument)
        Specifies a single argument for the executable. This method can be called multiple times.
        Parameters:
        argument - the argument
        Returns:
        itself
      • withArguments

        @Nonnull
        ProcessExecutor withArguments​(@Nonnull
                                      java.lang.String... arguments)
        Specifies some arguments for the executable. This method can be called multiple times.
        Parameters:
        arguments - the argument
        Returns:
        itself
      • withWorkingDirectory

        @Nonnull
        ProcessExecutor withWorkingDirectory​(@Nonnull
                                             java.nio.file.Path workingDirectory)
        Specifies the working directory for the executable.
        Parameters:
        workingDirectory - the working directory
        Returns:
        itself
      • start

        @Nonnull
        ProcessExecutor start()
                       throws java.io.IOException
        Launches the external process and starts collecting its output (which can be analyzed by calling getStdout() and getStderr().
        Returns:
        itself
        Throws:
        java.io.IOException - if something goes wrong
      • waitForCompletion

        @Nonnull
        ProcessExecutor waitForCompletion()
                                   throws java.io.IOException,
                                          java.lang.InterruptedException
        Waits for the completion of the external process. If the process terminates with a non-zero status code, an IOException is thrown.
        Returns:
        itself
        Throws:
        ProcessExecutorException - if the process terminates with a non zero exit code
        java.io.IOException - if something went wrong
        java.lang.InterruptedException - if the process has been interrupted
      • send

        @Nonnull
        ProcessExecutor send​(@Nonnull
                             java.lang.String string)
        Sends some input to the external process.
        Parameters:
        string - the input to send
        Returns:
        itself