class ExecUtil {

    public static String executeCommandLineAndWaitResponse(String commandLine, int timeout) {
        final Process process = internalExecute(commandLine);
        if (process != null) {
            try {
                process.waitFor(timeout, TimeUnit.MILLISECONDS);
                int exitCode = process.exitValue();
                final StringBuilder result = new StringBuilder();
                try (final BufferedReader reader = new BufferedReader(
                        new InputStreamReader(process.getInputStream()))) {
                    String line = "";
                    while ((line = reader.readLine()) != null) {
                        result.append(line).append("\n");
                    }
                }
                logger.debug("exit code '{}', result '{}'", exitCode, result);
                return result.toString();
            } catch (IOException e) {
                logger.debug("I/O exception occurred when executing commandLine '{}'", commandLine, e);
            } catch (InterruptedException e) {
                logger.warn("Timeout occurred when executing commandLine '{}'", commandLine);
                logger.debug("{}", e.getMessage(), e);
            }
        }
        return null;
    }

}