Class ExecUtil


  • public class ExecUtil
    extends Object
    • Constructor Detail

      • ExecUtil

        public ExecUtil()
    • Method Detail

      • exec

        public static boolean exec​(String command,
                                   String... args)
        Execute the specified command from within the current directory.
        Parameters:
        command - The command
        args - The command arguments
        Returns:
        true if commands where executed successfully
      • execWithTimeout

        public static boolean execWithTimeout​(Duration timeout,
                                              String command,
                                              String... args)
        Execute the specified command until the given timeout from within the current directory.
        Parameters:
        timeout - The timeout
        command - The command
        args - The command arguments
        Returns:
        true if commands where executed successfully
      • execSilent

        public static boolean execSilent​(String command,
                                         String... args)
        Execute the specified command from within the current directory and hide the output.
        Parameters:
        command - The command
        args - The command arguments
        Returns:
        true if commands where executed successfully
      • execSilentWithTimeout

        public static boolean execSilentWithTimeout​(Duration timeout,
                                                    String command,
                                                    String... args)
        Execute the specified command until the given timeout from within the current directory and hide the output.
        Parameters:
        timeout - The timeout
        command - The command
        args - The command arguments
        Returns:
        true if commands where executed successfully
      • exec

        public static boolean exec​(File directory,
                                   String command,
                                   String... args)
        Execute the specified command from within the specified directory.
        Parameters:
        directory - The directory
        command - The command
        args - The command arguments
        Returns:
        true if commands where executed successfully
      • execWithTimeout

        public static boolean execWithTimeout​(File directory,
                                              Duration timeout,
                                              String command,
                                              String... args)
        Execute the specified command until the given timeout from within the specified directory.
        Parameters:
        directory - The directory
        timeout - The timeout
        command - The command
        args - The command arguments
        Returns:
        true if commands where executed successfully
      • execSilent

        public static boolean execSilent​(File directory,
                                         String command,
                                         String... args)
        Execute the specified command from within the specified directory and hide the output.
        Parameters:
        directory - The directory
        command - The command
        args - The command arguments
        Returns:
        true if commands where executed successfully
      • execSilentWithTimeout

        public static boolean execSilentWithTimeout​(File directory,
                                                    Duration timeout,
                                                    String command,
                                                    String... args)
        Execute the specified command until the given timeout from within the specified directory and hide the output.
        Parameters:
        directory - The directory
        timeout - The timeout
        command - The command
        args - The command arguments
        Returns:
        true if commands where executed successfully
      • exec

        public static boolean exec​(File directory,
                                   Function<InputStream,​Runnable> outputFilterFunction,
                                   String command,
                                   String... args)
        Execute the specified command from within the specified directory. The method allows specifying an output filter that processes the command output.
        Parameters:
        directory - The directory
        outputFilterFunction - A Function that gets an InputStream and returns an outputFilter.
        command - The command
        args - The command arguments
        Returns:
        true if commands where executed successfully
      • execWithTimeout

        public static boolean execWithTimeout​(File directory,
                                              Function<InputStream,​Runnable> outputFilterFunction,
                                              Duration timeout,
                                              String command,
                                              String... args)
        Execute the specified command until the given timeout from within the specified directory. The method allows specifying an output filter that processes the command output.
        Parameters:
        directory - The directory
        outputFilterFunction - A Function that gets an InputStream and returns an outputFilter.
        timeout - The timeout
        command - The command
        args - The command arguments
        Returns:
        true if commands where executed successfully
      • startProcess

        public static Process startProcess​(File directory,
                                           String command,
                                           String... args)
        Start a process executing given command with arguments within the specified directory.
        Parameters:
        directory - The directory
        command - The command
        args - The command arguments
        Returns:
        the process
      • destroyProcess

        public static void destroyProcess​(Process process)
        Kill the process, if still alive, kill it forcibly
        Parameters:
        process - the process to kill