java.lang.Object
net.automatalib.common.util.process.ProcessUtil

public final class ProcessUtil extends Object
Utility class for invoking system processes.
  • Method Details

    • invokeProcess

      public static int invokeProcess(String[] commandLine) throws IOException, InterruptedException
      Runs the given set of command line arguments as a system process and returns the exit value of the spawned process. Discards any output of the process.
      Parameters:
      commandLine - the list of command line arguments to run
      Returns:
      the exit code of the process
      Throws:
      IOException - if an exception occurred while reading the process' outputs
      InterruptedException - if an exception occurred during process exception
    • invokeProcess

      public static int invokeProcess(List<String> commandLine) throws IOException, InterruptedException
      Runs the given set of command line arguments as a system process and returns the exit value of the spawned process. Discards any output of the process.
      Parameters:
      commandLine - the list of command line arguments to run
      Returns:
      the exit code of the process
      Throws:
      IOException - if an exception occurred while reading the process' outputs
      InterruptedException - if an exception occurred during process exception
    • invokeProcess

      public static int invokeProcess(String[] commandLine, Reader input) throws IOException, InterruptedException
      Runs the given set of command line arguments as a system process and returns the exit value of the spawned process. Additionally, allows one to supply an input stream to the invoked program. Discards any output of the process.
      Parameters:
      commandLine - the list of command line arguments to run
      input - the input passed to the program
      Returns:
      the exit code of the process
      Throws:
      IOException - if an exception occurred while reading the process' outputs, or writing the process' inputs
      InterruptedException - if an exception occurred during process exception
    • invokeProcess

      public static int invokeProcess(List<String> commandLine, Reader input) throws IOException, InterruptedException
      Runs the given set of command line arguments as a system process and returns the exit value of the spawned process. Additionally, allows one to supply an input stream to the invoked program. Discards any output of the process.
      Parameters:
      commandLine - the list of command line arguments to run
      input - the input passed to the program
      Returns:
      the exit code of the process
      Throws:
      IOException - if an exception occurred while reading the process' outputs, or writing the process' inputs
      InterruptedException - if an exception occurred during process exception
    • invokeProcess

      public static int invokeProcess(String[] commandLine, Consumer<String> stdOutConsumer, Consumer<String> stdErrConsumer) throws IOException, InterruptedException
      Runs the given set of command line arguments as a system process and returns the exit value of the spawned process. Outputs of the process (normal and error) are passed to the respective consumers.
      Parameters:
      commandLine - the list of command line arguments to run
      stdOutConsumer - the consumer for the program's standard output
      stdErrConsumer - the consumer for the program's error output
      Returns:
      the exit code of the process
      Throws:
      IOException - if an exception occurred while reading the process' outputs
      InterruptedException - if an exception occurred during process exception
    • invokeProcess

      public static int invokeProcess(List<String> commandLine, Consumer<String> stdOutConsumer, Consumer<String> stdErrConsumer) throws IOException, InterruptedException
      Runs the given set of command line arguments as a system process and returns the exit value of the spawned process. Outputs of the process (normal and error) are passed to the respective consumers such that each line results in a separate call to Consumer.accept(Object).
      Parameters:
      commandLine - the list of command line arguments to run
      stdOutConsumer - the consumer for the program's standard output
      stdErrConsumer - the consumer for the program's error output
      Returns:
      the exit code of the process
      Throws:
      IOException - if an exception occurred while reading the process' outputs
      InterruptedException - if an exception occurred during process exception
    • invokeProcess

      public static int invokeProcess(String[] commandLine, Reader input, Consumer<String> stdOutConsumer, Consumer<String> stdErrConsumer) throws IOException, InterruptedException
      Runs the given set of command line arguments as a system process and returns the exit value of the spawned process. Additionally, allows one to supply an input stream to the invoked program. Outputs of the process (normal and error) are passed to the respective consumers such that each line results in a separate call to Consumer.accept(Object).
      Parameters:
      commandLine - the list of command line arguments to run
      input - the input passed to the program
      stdOutConsumer - the consumer for the program's standard output
      stdErrConsumer - the consumer for the program's error output
      Returns:
      the exit code of the process
      Throws:
      IOException - if an exception occurred while reading the process' outputs, or writing the process' inputs
      InterruptedException - if an exception occurred during process exception
    • invokeProcess

      public static int invokeProcess(List<String> commandLine, @Nullable Reader input, Consumer<String> stdOutConsumer, Consumer<String> stdErrConsumer) throws IOException, InterruptedException
      Runs the given set of command line arguments as a system process and returns the exit value of the spawned process. Additionally, allows one to supply an input stream to the invoked program. Outputs of the process (normal and error) are passed to the respective consumers such that each line results in a separate call to Consumer.accept(Object).
      Parameters:
      commandLine - the list of command line arguments to run
      input - the input passed to the program
      stdOutConsumer - the consumer for the program's standard output
      stdErrConsumer - the consumer for the program's error output
      Returns:
      the exit code of the process
      Throws:
      IOException - if an exception occurred while reading the process' outputs, or writing the process' inputs
      InterruptedException - if the process is interrupted prior to finishing
    • invokeProcess

      public static int invokeProcess(String[] commandLine, Reader input, OutputStream stdOutConsumer, OutputStream stdErrConsumer) throws IOException, InterruptedException
      Runs the given set of command line arguments as a system process and returns the exit value of the spawned process. Additionally, allows one to supply an input stream to the invoked program. Outputs of the process (normal and error) are passed to the respective consumers.
      Parameters:
      commandLine - the list of command line arguments to run
      input - the input passed to the program
      stdOutConsumer - the consumer for the program's standard output
      stdErrConsumer - the consumer for the program's error output
      Returns:
      the exit code of the process
      Throws:
      IOException - if an exception occurred while reading the process' outputs, or writing the process' inputs
      InterruptedException - if the process is interrupted prior to finishing
    • invokeProcess

      public static int invokeProcess(List<String> commandLine, @Nullable Reader input, OutputStream stdOutConsumer, OutputStream stdErrConsumer) throws IOException, InterruptedException
      Runs the given set of command line arguments as a system process and returns the exit value of the spawned process. Additionally, allows one to supply an input stream to the invoked program. Outputs of the process (normal and error) are passed to the respective consumers.
      Parameters:
      commandLine - the list of command line arguments to run
      input - the input passed to the program
      stdOutConsumer - the consumer for the program's standard output
      stdErrConsumer - the consumer for the program's error output
      Returns:
      the exit code of the process
      Throws:
      IOException - if an exception occurred while reading the process' outputs, or writing the process' inputs
      InterruptedException - if the process is interrupted prior to finishing