Package com.logicaldoc.util.exec
Class Exec
- java.lang.Object
-
- com.logicaldoc.util.exec.Exec
-
public class Exec extends Object
Utility class used to execute system commands- Since:
- 6.3
- Author:
- Marco Meschieri - LogicalDOC
-
-
Constructor Summary
Constructors Constructor Description Exec()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringexec(String commandLine, String[] env, File dir)Execute the command by using the Runtime.getRuntime().exec()intexec(String commandLine, String[] env, File dir, int timeout)Execute the command by using the Runtime.execintexec(String commandLine, String[] env, File dir, Writer outputWriter, int timeout)intexec(String commandLine, String[] env, File dir, StringBuilder buffer, int timeout)intexec(List<String> commandLine)Execute the command by using the Runtime.getRuntime().exec()intexec(List<String> commandLine, String[] env, File dir, int timeout)Execute the command by using the Runtime.getRuntime().exec()intexec2(List<String> commandLine, File directory, int timeout)Executes the command by using the process builder.booleanisWindows()Checks if you are running on WindowsStringnormalizePathForCommand(String srcPath)Utility method for normalizing a path to be used to invoke a commandvoidsetErrPrefix(String errPrefix)voidsetOutPrefix(String outPrefix)
-
-
-
Method Detail
-
setErrPrefix
public void setErrPrefix(String errPrefix)
-
setOutPrefix
public void setOutPrefix(String outPrefix)
-
isWindows
public boolean isWindows()
Checks if you are running on Windows- Returns:
- true if the execution platform is Windows
-
exec2
public 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. The path of the command must be listed in the allowed-commands.txtdirectory- The folder where the command will be executedtimeout- The timeout in seconds- Returns:
- the return value
- Throws:
IOException- raised in case of errors during execution
-
exec
public 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. The path of the command must be listed in the allowed-commands.txt- Returns:
- the command execution return value
- Throws:
IOException- raised in case of errors during execution
-
exec
public 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. The path of the command must be listed in the allowed-commands.txtenv- the environment variablesdir- the current foldertimeout- maximum execution time expressed in seconds- Returns:
- the return code of the command
- Throws:
IOException- raised in case of errors during execution
-
exec
public 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. The path of the command must be listed in the allowed-commands.txtenv- the execution environmentdir- the current folder- Returns:
- The output of the command
- Throws:
IOException- If the execution caused an error
-
exec
public int exec(String commandLine, String[] env, File dir, StringBuilder buffer, int timeout) throws IOException
- Throws:
IOException
-
exec
public int exec(String commandLine, String[] env, File dir, Writer outputWriter, int timeout) throws IOException
- Throws:
IOException
-
exec
public 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. The path of the command must be listed in the allowed-commands.txtenv- the environment variablesdir- the current execution directorytimeout- maximum execution time expressed in seconds- Returns:
- the command return value
- Throws:
IOException- raised if the command produced an error
-
-