Class Exec


  • public class Exec
    extends Object
    Utility class used to execute system commands
    Since:
    6.3
    Author:
    Marco Meschieri - LogicalDOC
    • Constructor Detail

      • Exec

        public Exec()
    • Method Detail

      • isWindows

        public static boolean isWindows()
        Checks if you are running on Windows
        Returns:
        true if the execution platform is Windows
      • exec2

        public static int exec2​(List<String> commandLine,
                                File directory,
                                int timeout)
                         throws IOException
        Executes the command by using the process builder.
        Parameters:
        commandLine - The command line to process
        directory - The folder where the command will be executed
        timeout - The timeout in seconds
        Throws:
        IOException - raised in case of errors during execution
      • exec

        public static int exec​(List<String> commandLine)
                        throws IOException
        Execute the command by using the Runtime.getRuntime().exec()
        Parameters:
        commandLine - the list of elements in the command line
        Returns:
        the command execution return value
        Throws:
        IOException - raised in case of errors during execution
      • exec

        public static int exec​(List<String> commandLine,
                               String[] env,
                               File dir,
                               int timeout)
                        throws IOException
        Execute the command by using the Runtime.getRuntime().exec()
        Parameters:
        commandLine - the list of elements in the command line
        env - the environment variables
        dir - the current folder
        timeout - maximum execution time expressed in seconds
        Returns:
        the return code of the command
        Throws:
        IOException - raised in case of errors during execution
      • exec

        public static String exec​(String commandLine,
                                  String[] env,
                                  File dir)
                           throws IOException
        Execute the command by using the Runtime.getRuntime().exec()
        Parameters:
        commandLine - the command line string
        env - the execution environment
        dir - the current folder
        Returns:
        The output of the command
        Throws:
        IOException - If the execution caused an error
      • exec

        public static int exec​(String commandLine,
                               String[] env,
                               File dir,
                               int timeout)
                        throws IOException
        Execute the command by using the Runtime.exec
        Parameters:
        commandLine - the command line
        env - the environment variables
        dir - the current execution directory
        timeout - maximum execution time expressed in seconds
        Returns:
        the command return value
        Throws:
        IOException - raised if the command produced an error