Package io.github.connellite.util
Class ProcessRunner
java.lang.Object
io.github.connellite.util.ProcessRunner
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordOutcome of an OS process started byProcessRunner. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ProcessRunner.ProcessResultRunscommand(quoted tokens supported) with no timeout.static ProcessRunner.ProcessResultRunscommandwith no timeout.static ProcessRunner.ProcessResultRunscommandand waits up totimeout.static ProcessRunner.ProcessResultRunscommand(quoted tokens supported) and waits up totimeout.static ProcessRunner.ProcessResultRunscommandwith no timeout.static ProcessRunner.ProcessResultRunscommandviaProcessBuilder.static StringrunAndWaitFor(String command) Executes an OS command, waits for completion, and returns captured standard output.static StringrunAndWaitFor(String command, long timeout, TimeUnit unit) Executes an OS command, waits up totimeout, and returns captured standard output.static ObjectrunJar(byte[] jar) Deprecated.static ObjectDeprecated.No isolation; preferrun(List)withjava -jar.static ObjectDeprecated.No isolation; preferrun(List)withjava -jar.static ObjectDeprecated.No isolation; preferrun(List)withjava -jar.
-
Constructor Details
-
ProcessRunner
public ProcessRunner()
-
-
Method Details
-
runAndWaitFor
Executes an OS command, waits for completion, and returns captured standard output.- Throws:
IOExceptionInterruptedException
-
runAndWaitFor
public static String runAndWaitFor(String command, long timeout, TimeUnit unit) throws IOException, InterruptedException Executes an OS command, waits up totimeout, and returns captured standard output. On timeout the process is destroyed.- Throws:
IOExceptionInterruptedException
-
run
public static ProcessRunner.ProcessResult run(String command) throws IOException, InterruptedException Runscommand(quoted tokens supported) with no timeout.- Throws:
IOExceptionInterruptedException
-
run
public static ProcessRunner.ProcessResult run(String command, long timeout, TimeUnit unit) throws IOException, InterruptedException Runscommand(quoted tokens supported) and waits up totimeout.- Throws:
IOExceptionInterruptedException
-
run
public static ProcessRunner.ProcessResult run(String[] command) throws IOException, InterruptedException Runscommandwith no timeout.- Throws:
IOExceptionInterruptedException
-
run
public static ProcessRunner.ProcessResult run(String[] command, long timeout, TimeUnit unit) throws IOException, InterruptedException Runscommandand waits up totimeout.- Throws:
IOExceptionInterruptedException
-
run
public static ProcessRunner.ProcessResult run(List<String> command) throws IOException, InterruptedException Runscommandwith no timeout.- Throws:
IOExceptionInterruptedException
-
run
public static ProcessRunner.ProcessResult run(List<String> command, long timeout, TimeUnit unit) throws IOException, InterruptedException RunscommandviaProcessBuilder. Negativetimeoutwaits until exit. Both stdout and stderr are drained on extra threads. On timeout:Process.destroy(), thenProcess.destroyForcibly()if still alive.- Throws:
IOExceptionInterruptedException
-
runJar
Deprecated.No isolation; preferrun(List)withjava -jar.Loadsjarin-process and invokesMain-Class#main(String[]). -
runJar
@Deprecated public static Object runJar(File jar, String methodName) throws IOException, ReflectiveOperationException Deprecated.No isolation; preferrun(List)withjava -jar.Loadsjarin-process and invokes a no-arg method onMain-Class. -
runJar
@Deprecated public static Object runJar(byte[] jar) throws IOException, ReflectiveOperationException Deprecated.No isolation; preferrun(List)withjava -jar.Loadsjarbytes in-process and invokesMain-Class#main(String[]). -
runJar
@Deprecated public static Object runJar(byte[] jar, String methodName) throws IOException, ReflectiveOperationException Deprecated.No isolation; preferrun(List)withjava -jar.Loadsjarbytes in-process and invokes a no-arg method onMain-Class.
-
run(List)withjava -jar.