Package org.javalite.common
Class RuntimeUtil
java.lang.Object
org.javalite.common.RuntimeUtil
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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic RuntimeUtil.Response
Executes an external command and provides results of execution.static RuntimeUtil.Response
Executes an external command and provides results of execution.static RuntimeUtil.Response
Executes an external command and provides results of execution at the current location.static RuntimeUtil.Response
Convenience method, does the same asexecute(String...)
, but will automatically convert a full command string to tokens for convenience.static RuntimeUtil.Response
Executes an external command and provides results of execution.
-
Constructor Details
-
RuntimeUtil
public RuntimeUtil()
-
-
Method Details
-
execute
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.Response
with 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. Passnull
to 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.Response
with result of execution.
-
execute
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. Passnull
to execute at current location of the calling process.- Returns:
- instance of
RuntimeUtil.Response
with result of execution.
-
execute
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.Response
with result of execution.
-
execute
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.Response
with result of execution.
-