Class ProcessHelpers
java.lang.Object
org.kiwiproject.beta.base.process.ProcessHelpers
Utilities to execute a command using a
ProcessHelper.
These static methods could be considered for addition to kiwi's ProcessHelper.
They would be instance methods inside ProcessHelper. Static versions of the methods could also be
added to kiwi's Processes class (which contains only static utilities), and then the instance
methods in ProcessHelper would delegate, thereby providing two ways to use this. Using ProcessHelper
is more friendly to testing since it can easily be mocked.
-
Method Summary
Modifier and TypeMethodDescriptionstatic ProcessResultExecute command with timeout of 5 seconds.static ProcessResultexecute(org.kiwiproject.base.process.ProcessHelper processHelper, List<String> command, long timeout, TimeUnit timeoutUnit) Execute command with the given timeout.static ProcessResultexecute(org.kiwiproject.base.process.ProcessHelper processHelper, List<String> command, Duration timeout) Execute command with the given timeout.
-
Method Details
-
execute
public static ProcessResult execute(org.kiwiproject.base.process.ProcessHelper processHelper, List<String> command) Execute command with timeout of 5 seconds.- Implementation Note:
- See the implementation note in
execute(ProcessHelper, List, long, TimeUnit).
-
execute
public static ProcessResult execute(org.kiwiproject.base.process.ProcessHelper processHelper, List<String> command, Duration timeout) Execute command with the given timeout. -
execute
public static ProcessResult execute(org.kiwiproject.base.process.ProcessHelper processHelper, List<String> command, long timeout, TimeUnit timeoutUnit) Execute command with the given timeout.- Implementation Note:
- This uses
CompletableFutureto ensure we time out even if the stdout or stderr blocks, which according to theProcessdocs, can at least theoretically happen. For example, if someone gives the commandls -laR /to list all files in the filesystem, it will probably take quite a long time.
-