ProcessBuilder prepareShellCommand(ServiceInfo.ServiceAdvisorType serviceAdvisorType, String script,
                                     StackAdvisorCommandType saCommandType,
                                     File actionDirectory, String outputFile, String errorFile) {
    String hostsFile = actionDirectory + File.separator + "hosts.json";
    String servicesFile = actionDirectory + File.separator + "services.json";

    // includes the original command plus the arguments for it
    List<String> builderParameters = new ArrayList<>();

    switch (serviceAdvisorType) {
      case PYTHON:
      case JAVA:
        if (System.getProperty("os.name").contains("Windows")) {
          builderParameters.add("cmd");
          builderParameters.add("/c");
        } else {
          builderParameters.add("sh");
          builderParameters.add("-c");
        }
        break;
      default:
        break;
    }

    // for the 3rd argument, build a single parameter since we use -c
    // ProcessBuilder doesn't support output redirection until JDK 1.7
    String commandStringParameters[] = new String[] {script, saCommandType.toString(), hostsFile, servicesFile, "1>", outputFile, "2>", errorFile};

    StringBuilder commandString = new StringBuilder();
    for (String command : commandStringParameters) {
      commandString.append(command).append(" ");
    }

    builderParameters.add(commandString.toString());

    LOG.debug("StackAdvisorRunner. Stack advisor command is {}", StringUtils.join(" ", builderParameters));

    return new ProcessBuilder(builderParameters);
  }
Gets an instance of a {@link ProcessBuilder} that's ready to execute the
shell command to run the stack advisor script. This will take the
environment variables from the current process.

@param serviceAdvisorType Python or Java
@param script Python script or jar path
@param saCommandType command type such as validate, configure
@param actionDirectory Directory that contains hosts.json, services.json, and output files
@param outputFile Output file path
@param errorFile Error file path
@return Process that can launch
ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorRunner.java