Package no.polaric.core.util
Class ProcessRunner
java.lang.Object
no.polaric.core.util.ProcessRunner
Utility class for running external processes.
Provides a cleaner alternative to Runtime.getRuntime().exec().
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classResult of a process execution. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ProcessRunner.ProcessResultExecute a command and wait for it to complete.static ProcessRunner.ProcessResultExecute a command with separate arguments and wait for it to complete.
-
Constructor Details
-
ProcessRunner
public ProcessRunner()
-
-
Method Details
-
execute
public static ProcessRunner.ProcessResult execute(String command) throws IOException, InterruptedException Execute a command and wait for it to complete.- Parameters:
command- The command to execute (can be a single string or array of arguments)- Returns:
- ProcessResult containing exit code, output, and error streams
- Throws:
IOException- if an I/O error occursInterruptedException- if the thread is interrupted while waiting
-
execute
public static ProcessRunner.ProcessResult execute(String[] cmdarray) throws IOException, InterruptedException Execute a command with separate arguments and wait for it to complete.- Parameters:
cmdarray- Array containing the command and its arguments- Returns:
- ProcessResult containing exit code, output, and error streams
- Throws:
IOException- if an I/O error occursInterruptedException- if the thread is interrupted while waiting
-