class ExternalProcessRunner {

    public ProcessResult executeAndThrowOnFailure(String command, String... args) throws ProcessNotExecutableException,
            ProcessFailedException, InterruptedException {
        ProcessResult processResult = execute(command, args);
        // if the process fails we attach the output into the exception
        if (processResult.getExitCode() != 0) {
            String processOutputString = processOutputToString(processResult.processOutput);
            String errorMsg = String.format("Failed to run command '%s' with output: %n %s",
                    processResult.commandWithArgs, processOutputString);
            log.error(errorMsg);
            throw new ProcessFailedException(errorMsg, processResult.processOutput);
        }
        return processResult;
    }

}