Class ShellCommandExecutor


  • public class ShellCommandExecutor
    extends Object
    • Constructor Detail

      • ShellCommandExecutor

        public ShellCommandExecutor​(File executionFolder,
                                    Map<String,​String> environment,
                                    long timeoutMillis)
    • Method Detail

      • executeCommand

        public <T> T executeCommand​(ShellCommandExecutor.OutputParser<T> outputParser,
                                    String... command)
                             throws IOException,
                                    InterruptedException,
                                    TimeoutException
        Executes given shell command and returns parsed output
        Type Parameters:
        T - Type of parsed command output
        Parameters:
        outputParser - Parses that is used to process command output
        command - Command to be executed
        Returns:
        Parsed command output
        Throws:
        IOException - If an error was encountered while writing command input or reading output
        TimeoutException - If timeout was reached while waiting for command to finish
        InterruptedException - If current thread was interrupted while waiting for command to finish
      • executeCommand

        public <T> T executeCommand​(ShellCommandExecutor.OutputParser<T> outputParser,
                                    byte[] input,
                                    String... command)
                             throws IOException,
                                    InterruptedException,
                                    TimeoutException
        Executes given shell command, supplies to it provided input, and returns parsed output
        Type Parameters:
        T - Type of parsed command output
        Parameters:
        outputParser - Parses that is used to process command output
        input - Bytes that are written to command's input stream
        command - Command to be executed
        Returns:
        Parsed command output
        Throws:
        IOException - If an error was encountered while writing command input or reading output
        TimeoutException - If timeout was reached while waiting for command to finish
        InterruptedException - If current thread was interrupted while waiting for command to finish
      • executeCommandReadingError

        public <T> T executeCommandReadingError​(ShellCommandExecutor.OutputParser<T> errorParser,
                                                String... command)
                                         throws IOException,
                                                InterruptedException,
                                                TimeoutException
        Executes given shell command and returns parsed error stream
        Type Parameters:
        T - Type of parsed command output
        Parameters:
        errorParser - Parses that is used to process command's error stream
        command - Command to be executed
        Returns:
        Parsed command output
        Throws:
        IOException - If an error was encountered while writing command input or reading output
        TimeoutException - If timeout was reached while waiting for command to finish
        InterruptedException - If current thread was interrupted while waiting for command to finish