Package org.javalite.common
Class RuntimeUtil
- java.lang.Object
-
- org.javalite.common.RuntimeUtil
-
public class RuntimeUtil extends Object
Utility class to shell out system commands. Use for quick execution of external processes that will not generate a lot of output.- Author:
- igor on 1/20/17.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRuntimeUtil.Response
-
Constructor Summary
Constructors Constructor Description RuntimeUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static RuntimeUtil.Responseexecute(int maxBuffer, File dir, String... command)Executes an external command and provides results of execution.static RuntimeUtil.Responseexecute(int maxBuffer, File dir, List<String> envVars, String... command)Executes an external command and provides results of execution.static RuntimeUtil.Responseexecute(int maxBuffer, String... command)Executes an external command and provides results of execution at the current location.static RuntimeUtil.Responseexecute(String command)Convenience method, does the same asexecute(String...), but will automatically convert a full command string to tokens for convenience.static RuntimeUtil.Responseexecute(String... command)Executes an external command and provides results of execution.
-
-
-
Method Detail
-
execute
public static RuntimeUtil.Response execute(int maxBuffer, String... command)
Executes an external command and provides results of execution at the current location. Will accumulate limited output from the external process.- Parameters:
command- array containing the command to call and its arguments.maxBuffer- max size of buffersout, err. An external process may produce a lot of output, be careful setting to a large value. The buffer will not be allocated to this size at the start, but will grow until it reaches it. The program will continue toi execute, and the buffer will be 'tailing' the output of the external process.- Returns:
- instance of
RuntimeUtil.Responsewith result of execution.
-
execute
public static RuntimeUtil.Response execute(int maxBuffer, File dir, List<String> envVars, String... command)
Executes an external command and provides results of execution. Will accumulate limited output from the external process.- Parameters:
command- array containing the command to call and its arguments.maxBuffer- max size of buffersout, err. An external process may produce a lot of output, be careful setting to a large value. The buffer will not be allocated to this this size at the start, but will grow until it reaches it. The program will continue toi execute, and the buffer will be 'tailing' the output of the external process.dir- - location of process execution. Passnullto execute at current location of the calling process.envVars- a list of environment variables to pass to the process. The format for each string in a list: "name=value".- Returns:
- instance of
RuntimeUtil.Responsewith result of execution.
-
execute
public static RuntimeUtil.Response execute(int maxBuffer, File dir, String... command)
Executes an external command and provides results of execution. Will accumulate limited output from the external process.- Parameters:
command- array containing the command to call and its arguments.maxBuffer- max size of buffersout, err. An external process may produce a lot of output, be careful setting to a large value. The buffer will not be allocated to this this size at the start, but will grow until it reaches it. The program will continue to execute, and the buffer will be 'tailing' the output of the external process.dir- - location of process execution. Passnullto execute at current location of the calling process.- Returns:
- instance of
RuntimeUtil.Responsewith result of execution.
-
execute
public static RuntimeUtil.Response execute(String... command)
Executes an external command and provides results of execution. Will accumulate limited output from the external process. Defaults to max 2048 characters in each buffer: out, err and only shows the tail of each buffer.- Parameters:
command- array containing the command to call and its arguments.- Returns:
- instance of
RuntimeUtil.Responsewith result of execution.
-
execute
public static RuntimeUtil.Response execute(String command)
Convenience method, does the same asexecute(String...), but will automatically convert a full command string to tokens for convenience. Here is how to call:System.out.println(execute("ls -ls").out);- Parameters:
command- - a single string representing a command and its arguments.- Returns:
- instance of
RuntimeUtil.Responsewith result of execution.
-
-