Class ProcessHelpers


  • @Beta
    public final class ProcessHelpers
    extends Object
    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 Detail

      • execute

        public static ProcessResult execute​(org.kiwiproject.base.process.ProcessHelper processHelper,
                                            List<String> command,
                                            int timeout,
                                            TimeUnit timeoutUnit)
        Execute command with the given timeout.
        Implementation Note:
        This uses CompletableFuture to ensure we time out even if the stdout or stderr blocks, which according to the Process docs, can at least theoretically happen. For example, if someone gives the command ls -laR / to list all files in the filesystem, it will probably take quite a long time.