java.lang.Object
xyz.ronella.trivial.handy.CommandRunner
Run external command.
- Since:
- 2.5.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BiConsumer<InputStream,InputStream> The default output logic implementation that just simply print the output stream to System.out and error stream to System.err.static final intThe ERROR_EXIT_CODE when exception occurred running the command. -
Method Summary
Modifier and TypeMethodDescriptionstatic intrunCommand(String... command) Run the commands received.static intrunCommand(BiConsumer<InputStream, InputStream> outputLogic, String... command) Run the commands received.static intrunCommand(BiConsumer<InputStream, InputStream> outputLogic, ICommandArray commandArray) Start a process based on the command received.static intrunCommand(Consumer<ProcessBuilder> initProcessBuilder, String... command) Run the commands received.static intrunCommand(Consumer<ProcessBuilder> initProcessBuilder, BiConsumer<InputStream, InputStream> outputLogic, String... command) Run the commands received.static intrunCommand(Consumer<ProcessBuilder> initProcessBuilder, BiConsumer<InputStream, InputStream> outputLogic, ICommandArray commandArray) Run the commands received.static intrunCommand(Consumer<ProcessBuilder> initProcessBuilder, ICommandArray commandArray) Run the commands received.static intrunCommand(Supplier<ProcessBuilder> createProcessBuilder, String... command) Run the commands received.static intrunCommand(Supplier<ProcessBuilder> createProcessBuilder, BiConsumer<InputStream, InputStream> outputLogic, String... command) Run the commands received.static intrunCommand(Supplier<ProcessBuilder> createProcessBuilder, BiConsumer<InputStream, InputStream> outputLogic, ICommandArray commandArray) Run the commands received.static intrunCommand(Supplier<ProcessBuilder> createProcessBuilder, ICommandArray commandArray) Run the commands received.static intrunCommand(ICommandArray commandArray) Run the commands received.static ProcessstartProcess(Consumer<Process> initProcess, ICommandArray commandArray) Start a process based on the command received.static ProcessstartProcess(Consumer<ProcessBuilder> initProcessBuilder, Consumer<Process> initProcess, ICommandArray commandArray) Start a process based on the command received.static ProcessstartProcess(Supplier<ProcessBuilder> createProcessBuilder, Consumer<Process> initProcess, BiConsumer<InputStream, InputStream> outputLogic, ICommandArray commandArray) Start a process based on the command received.static ProcessstartProcess(Supplier<ProcessBuilder> createProcessBuilder, Consumer<Process> initProcess, ICommandArray commandArray) Start a process based on the command received.static ProcessstartProcess(ICommandArray commandArray) Start a process based on the command received.
-
Field Details
-
ERROR_EXIT_CODE
public static final int ERROR_EXIT_CODEThe ERROR_EXIT_CODE when exception occurred running the command.- See Also:
-
DEFAULT_OUTPUT_LOGIC
The default output logic implementation that just simply print the output stream to System.out and error stream to System.err.
-
-
Method Details
-
runCommand
public static int runCommand(Supplier<ProcessBuilder> createProcessBuilder, String... command) throws MissingCommandException Run the commands received.- Parameters:
createProcessBuilder- Manually creates an instance of ProcessBuilder.command- The commands to be executed.- Returns:
- The exit code after the completion of the process.
- Throws:
MissingCommandException- Thrown when no command was passed.
-
runCommand
public static int runCommand(Supplier<ProcessBuilder> createProcessBuilder, ICommandArray commandArray) throws MissingCommandException Run the commands received.- Parameters:
createProcessBuilder- Manually creates an instance of ProcessBuilder.commandArray- An implementation of ICommandArray.- Returns:
- The exit code after the completion of the process.
- Throws:
MissingCommandException- Thrown when no command was passed.- Since:
- 2.10.0
-
runCommand
public static int runCommand(Consumer<ProcessBuilder> initProcessBuilder, String... command) throws MissingCommandException Run the commands received.- Parameters:
initProcessBuilder- Must hold the additional initialization logic for ProcessBuilder.command- The commands to be executed.- Returns:
- The exit code after the completion of the process.
- Throws:
MissingCommandException- Thrown when no command was passed.- Since:
- 2.13.0
-
runCommand
public static int runCommand(Consumer<ProcessBuilder> initProcessBuilder, ICommandArray commandArray) throws MissingCommandException Run the commands received.- Parameters:
initProcessBuilder- Must hold the additional initialization logic for ProcessBuilder.commandArray- An implementation of ICommandArray.- Returns:
- The exit code after the completion of the process.
- Throws:
MissingCommandException- Thrown when no command was passed.- Since:
- 2.10.0
-
runCommand
Run the commands received.- Parameters:
commandArray- An implementation of ICommandArray.- Returns:
- The exit code after the completion of the process.
- Throws:
MissingCommandException- Thrown when no command was passed.- Since:
- 2.10.0
-
runCommand
Run the commands received.- Parameters:
command- The commands to be executed.- Returns:
- The exit code after the completion of the process.
- Throws:
MissingCommandException- Thrown when no command was passed.
-
runCommand
public static int runCommand(BiConsumer<InputStream, InputStream> outputLogic, String... command) throws MissingCommandExceptionRun the commands received.- Parameters:
command- The commands to be executed.outputLogic- Must hold the logic on dealing with the output and error result.- Returns:
- The exit code after the completion of the process.
- Throws:
MissingCommandException- Thrown when no command was passed.
-
runCommand
public static int runCommand(BiConsumer<InputStream, InputStream> outputLogic, ICommandArray commandArray) throws MissingCommandExceptionStart a process based on the command received.- Parameters:
commandArray- An implementation of ICommandArray.outputLogic- Must hold the logic on dealing with the output and error result.- Returns:
- The exit code after the completion of the process.
- Throws:
MissingCommandException- Thrown when no command was passed.- Since:
- 2.10.0
-
startProcess
public static Process startProcess(Consumer<Process> initProcess, ICommandArray commandArray) throws MissingCommandException, CommandRunnerException Start a process based on the command received.- Parameters:
commandArray- An implementation of ICommandArray.initProcess- Manually initialize the instance of Process.- Returns:
- An instance of Process.
- Throws:
MissingCommandException- Thrown when no command was passed.CommandRunnerException- Thrown when CommandRunner encountered an error.- Since:
- 2.13.0
-
startProcess
public static Process startProcess(ICommandArray commandArray) throws MissingCommandException, CommandRunnerException Start a process based on the command received.- Parameters:
commandArray- An implementation of ICommandArray.- Returns:
- An instance of Process.
- Throws:
MissingCommandException- Thrown when no command was passed.CommandRunnerException- Thrown when CommandRunner encountered an error.- Since:
- 2.14.0
-
runCommand
public static int runCommand(Consumer<ProcessBuilder> initProcessBuilder, BiConsumer<InputStream, InputStream> outputLogic, String... command) throws MissingCommandExceptionRun the commands received.- Parameters:
initProcessBuilder- Must hold the additional initialization logic for ProcessBuilder.outputLogic- Must hold the logic on dealing with the output and error result.command- The commands to be executed.- Returns:
- The exit code after the completion of the process.
- Throws:
MissingCommandException- Thrown when no command was passed.
-
runCommand
public static int runCommand(Consumer<ProcessBuilder> initProcessBuilder, BiConsumer<InputStream, InputStream> outputLogic, ICommandArray commandArray) throws MissingCommandExceptionRun the commands received.- Parameters:
initProcessBuilder- Must hold the additional initialization logic for ProcessBuilder.outputLogic- Must hold the logic on dealing with the output and error result.commandArray- An implementation of ICommandArray.- Returns:
- The exit code after the completion of the process.
- Throws:
MissingCommandException- Thrown when no command was passed.- Since:
- 2.10.0
-
startProcess
public static Process startProcess(Consumer<ProcessBuilder> initProcessBuilder, Consumer<Process> initProcess, ICommandArray commandArray) throws MissingCommandException, CommandRunnerException Start a process based on the command received.- Parameters:
initProcessBuilder- Must hold the additional initialization logic for ProcessBuilder.initProcess- Manually initialize the instance of Process.commandArray- An implementation of ICommandArray.- Returns:
- An instance of Process.
- Throws:
MissingCommandException- Thrown when no command was passed.CommandRunnerException- Thrown when CommandRunner encountered an error.- Since:
- 2.13.0
-
runCommand
public static int runCommand(Supplier<ProcessBuilder> createProcessBuilder, BiConsumer<InputStream, InputStream> outputLogic, ICommandArray commandArray) throws MissingCommandExceptionRun the commands received.- Parameters:
createProcessBuilder- Manually creates an instance of ProcessBuilder.outputLogic- Must hold the logic on dealing with the output and error result.commandArray- An implementation of ICommandArray.- Returns:
- The exit code after the completion of the process.
- Throws:
MissingCommandException- Thrown when no command was passed.- Since:
- 2.10.0
-
startProcess
public static Process startProcess(Supplier<ProcessBuilder> createProcessBuilder, Consumer<Process> initProcess, ICommandArray commandArray) throws MissingCommandException, CommandRunnerException Start a process based on the command received.- Parameters:
createProcessBuilder- Manually creates an instance of ProcessBuilder.initProcess- Manually initialize the instance of Process.commandArray- An implementation of ICommandArray.- Returns:
- An instance of Process.
- Throws:
MissingCommandException- Thrown when no command was passed.CommandRunnerException- Thrown when CommandRunner encountered an error.- Since:
- 2.13.0
-
runCommand
public static int runCommand(Supplier<ProcessBuilder> createProcessBuilder, BiConsumer<InputStream, InputStream> outputLogic, String... command) throws MissingCommandExceptionRun the commands received.- Parameters:
createProcessBuilder- Manually creates an instance of ProcessBuilder.outputLogic- Must hold the logic on dealing with the output and error result.command- The commands to be executed.- Returns:
- The exit code after the completion of the process.
- Throws:
MissingCommandException- Thrown when no command was passed.
-
startProcess
public static Process startProcess(Supplier<ProcessBuilder> createProcessBuilder, Consumer<Process> initProcess, BiConsumer<InputStream, InputStream> outputLogic, ICommandArray commandArray) throws MissingCommandException, CommandRunnerExceptionStart a process based on the command received.- Parameters:
createProcessBuilder- Manually creates an instance of ProcessBuilder.initProcess- Manually initialize the instance of Process.outputLogic- Must hold the logic on dealing with the output and error result.commandArray- An implementation of ICommandArray.- Returns:
- An instance of Process.
- Throws:
MissingCommandException- Thrown when no command was passed.CommandRunnerException- Thrown when CommandRunner encountered an error.- Since:
- 2.13.0
-