public static String executeCommand()

in azure-sfmesh-maven-plugin/src/main/java/com/microsoft/azure/maven/servicefabric/Utils.java [71:105]


    public static String executeCommand(Log logger, String command) throws MojoFailureException{
        try {
            logger.info(String.format("Executing command %s", command));
            final Process p;
            if (Utils.isWindows()){
                p = Runtime.getRuntime().exec("cmd.exe /C" + command);
            } else {
                p = Runtime.getRuntime().exec(command);
            }
            p.waitFor();
            final int exitCode = p.exitValue();
            final String stderr = IOUtil.toString(p.getErrorStream(), "UTF-8");
            final String stdout = IOUtil.toString(p.getInputStream(), "UTF-8");
            logger.debug(String.format("STDOUT: %s", stdout));
            if (stderr != null && stderr.length() > 0){
                if (exitCode != 0){
                    logger.error(String.format("Process exited with exit code %d", exitCode));
                    logger.error(String.format("If STDERR: %s", stderr));
                    throw new MojoFailureException(String.format("Error while " +
                        "running the %s command", command));
                } else {
                    logger.info(String.format("Else STDERR: %s", stderr));
                }
            }
            return stdout;
        } catch (IOException e){
            logger.error(e);
            throw new MojoFailureException(String.format("Error while " +
                "running the %s command", command));
        } catch (InterruptedException e) {
            logger.error(e);
            throw new MojoFailureException(String.format("Interrupted while " +
                "running command %s", command));
        }
    }