| Modifier and Type | Field and Description |
|---|---|
| private final List | |
| private final Map | |
| private boolean | |
| private final Logger | |
| private boolean | |
| private final StringBuffer | |
| private final List |
| Access | Constructor and Description |
|---|---|
| public | CommandRunner(String...
command line arguments to be executed by the process. args)Initializes CommandRunner with default logger and command line arguments. |
| public | CommandRunner(Logger
Logger instance for logging process activities. logger, @NotNull String... Command line arguments to be executed by the process. args)Initializes CommandRunner with specified logger and command line arguments. |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| public void | addArgs(@NotNull Collection<String>
a collection of arguments args)Adds a collection of arguments to the existing list of command line of arguments |
| public void | addSecretArg(@Nullable String
a string passed to the command line arguments arg)Adds a command line argument to the list of existing list of command line arguments, marking it as secret argument, in order to avoid logging |
| public void | |
| public String | |
| public List | |
| public String | Returns: a string with the last line of the outputGets the last line of the output process. |
| public @Nullable String | Returns: a single string with the whole output of the processGets the response of the process as single string. |
| public @NotNull List | Returns: a list with all the lines of the outputGets the response of the process as list of lines. |
| private Thread | Returns: a thread that captures the process outputthe input stream of the process inputStream)Captures the process output, logging it and appending to an internal buffer. |
| public int | |
| public int | Returns: 0 if the process ends successfully, non-zero values indicate a failurethe name of the process processName, @Nullable File a file with the working directory of the process workingDirectory)Runs a process with a given set of command line arguments, in a given working directory. |
| public Process | |
| public Process | |
| public Process | |
| public Process | Returns: theProcess objectthe name of the process processName, @Nullable File a file with the working directory of the process workingDirectory, boolean a boolean that sets the merge output mode mergeOutput)Runs a process asynchronously with a given set of command line arguments, in a given working directory. |
| public boolean | |
| public boolean | Returns: true if the process ended successfully, false otherwisethe name of the process processName, @Nullable File a file with the working directory of the process workingDirectory, long the maximum time allowed to run the process timeout)Runs a process with a given set of command line arguments, in a given working directory, within a given time frame |
| public void | setInteractive(boolean
a boolean that sets the interactive mode interactive)When set to true, it will enable user interaction during the process. |
| public void | setPrintToConsole(boolean
a boolean that sets the print to console mode printToConsole)When set to true, it will enable the process output to be printed to the console. |
| private Process | Returns: the process objectthe name of the process processName, final File the working directory of the process directory)Prepares the process for execution. |
| args | back to summary |
|---|---|
| private final List<String> args | |
| envVars | back to summary |
|---|---|
| private final Map<String, String> envVars | |
| interactive | back to summary |
|---|---|
| private boolean interactive | |
| logger | back to summary |
|---|---|
| private final Logger logger | |
| printToConsole | back to summary |
|---|---|
| private boolean printToConsole | |
| processOutput | back to summary |
|---|---|
| private final StringBuffer processOutput | |
| secretArgs | back to summary |
|---|---|
| private final List<String> secretArgs | |
| CommandRunner | back to summary |
|---|---|
| public CommandRunner(String... args) Initializes CommandRunner with default logger and command line arguments.
| |
| CommandRunner | back to summary |
|---|---|
| public CommandRunner(Logger logger, @NotNull String... args) Initializes CommandRunner with specified logger and command line arguments. | |
| addArg | back to summary |
|---|---|
| public void addArg(@NotNull String arg) Adds a command line argument to the list of existing list of command line arguments | |
| addArgs | back to summary |
|---|---|
| public void addArgs(@NotNull String... args) Adds a varargs list of arguments to the existing list of command line of arguments | |
| addArgs | back to summary |
|---|---|
| public void addArgs(@NotNull Collection<String> args) Adds a collection of arguments to the existing list of command line of arguments
| |
| addSecretArg | back to summary |
|---|---|
| public void addSecretArg(@Nullable String arg) Adds a command line argument to the list of existing list of command line arguments, marking it as secret argument, in order to avoid logging | |
| addToEnv | back to summary |
|---|---|
| public void addToEnv(@NotNull String key, @NotNull String value) Adds a pair (key, value) to the environment map of the process. | |
| getCmd | back to summary |
|---|---|
public String getCmd()
| |
| getCmdList | back to summary |
|---|---|
| public List | |
| getLastResponse | back to summary |
|---|---|
| public String getLastResponse() Gets the last line of the output process.
| |
| getResponse | back to summary |
|---|---|
| public @Nullable String getResponse() Gets the response of the process as single string. | |
| getResponses | back to summary |
|---|---|
| public @NotNull List Gets the response of the process as list of lines. | |
| mergeProcessOutput | back to summary |
|---|---|
| private Thread mergeProcessOutput(final InputStream inputStream) Captures the process output, logging it and appending to an internal buffer.
| |
| run | back to summary |
|---|---|
| public int run(@Nullable String processName) throws IOException, InterruptedException Runs a process with a given set of command line arguments.
| |
| run | back to summary |
|---|---|
| public int run(@Nullable String processName, @Nullable File workingDirectory) throws IOException, InterruptedException Runs a process with a given set of command line arguments, in a given working directory.
| |
| runAsync | back to summary |
|---|---|
| public Process runAsync(@Nullable String processName) throws IOException Runs a process asynchronously with a given set of command line arguments. By default, it merges the output of the process.
| |
| runAsync | back to summary |
|---|---|
| public Process runAsync(@Nullable String processName, @Nullable File workingDirectory) throws IOException Runs a process asynchronously with a given set of command line arguments, in a given working directory. By default, it merges the output of the process. | |
| runAsync | back to summary |
|---|---|
| public Process runAsync(@Nullable String processName, boolean mergeOutput) throws IOException Runs a process asynchronously with a given set of command line arguments.
| |
| runAsync | back to summary |
|---|---|
| public Process runAsync(@Nullable String processName, @Nullable File workingDirectory, boolean mergeOutput) throws IOException Runs a process asynchronously with a given set of command line arguments, in a given working directory. | |
| runTimed | back to summary |
|---|---|
| public boolean runTimed(@Nullable String processName, long timeout) throws IOException, InterruptedException Runs a process with a given set of command line arguments within a given time frame.
| |
| runTimed | back to summary |
|---|---|
| public boolean runTimed(@Nullable String processName, @Nullable File workingDirectory, long timeout) throws IOException, InterruptedException Runs a process with a given set of command line arguments, in a given working directory, within a given time frame
| |
| setInteractive | back to summary |
|---|---|
| public void setInteractive(boolean interactive) When set to true, it will enable user interaction during the process. By default, is false
| |
| setPrintToConsole | back to summary |
|---|---|
| public void setPrintToConsole(boolean printToConsole) When set to true, it will enable the process output to be printed to the console. By default, is false
| |
| setupProcess | back to summary |
|---|---|
| private Process setupProcess(final String processName, final File directory) throws IOException Prepares the process for execution.
| |