Class ProcessUtils


  • public final class ProcessUtils
    extends Object
    Useful methods for working with processes.
    Author:
    Johannes Schindelin
    • Method Detail

      • exec

        public static String exec​(File workingDirectory,
                                  PrintStream err,
                                  PrintStream out,
                                  String... args)
        Executes a program. This is a convenience method mainly to be able to catch the output of programs as shell scripts can do by wrapping calls in $(...).
        Parameters:
        workingDirectory - the directory in which to execute the program
        err - the PrintStream to print the program's error stream to; if null is passed, the error goes straight to Nirvana (not the band, though).
        out - the PrintStream to print the program's output to; if null is passed, the output will be accumulated into a String and returned upon exit.
        args - the command-line to execute, split into components
        Returns:
        the output of the program if out is null, otherwise an empty String
        Throws:
        RuntimeException - if interrupted or the program failed to execute successfully.
      • exec

        public static String exec​(File workingDirectory,
                                  InputStream in,
                                  PrintStream err,
                                  PrintStream out,
                                  String... args)
        Executes a program. This is a convenience method mainly to be able to catch the output of programs as shell scripts can do by wrapping calls in $(...).
        Parameters:
        workingDirectory - the directory in which to execute the program
        in - the InputStream which gets fed to the program as standard input;
        err - the PrintStream to print the program's error stream to; if null is passed, the error goes straight to Nirvana (not the band, though).
        out - the PrintStream to print the program's output to; if null is passed, the output will be accumulated into a String and returned upon exit.
        args - the command-line to execute, split into components
        Returns:
        the output of the program if out is null, otherwise an empty String
        Throws:
        RuntimeException - if interrupted or the program failed to execute successfully.