public static String runCmd(File directory,List<String> cmd,String errorMessage) throws Exception {
  ProcessBuilder pb=new ProcessBuilder(cmd);
  pb.directory(directory);
  pb.redirectErrorStream(true);
  Process p=pb.start();
  String s;
  StringBuilder sb=new StringBuilder();
  BufferedReader stdout=new BufferedReader(new InputStreamReader(p.getInputStream()));
  while ((s=stdout.readLine()) != null) {
    logger.info(s);
    sb.append(s);
    sb.append('\n');
  }
  String sbs=sb.toString();
  int exitValue=p.waitFor();
  if (exitValue != 0)   throw new Exception(errorMessage + " exit value " + exitValue+ "  "+ sbs);
  return sbs;
}

public static String runCmd ( File directory , List < String > cmd , String errorMessage ) throws Exception { ProcessBuilder pb = new ProcessBuilder ( cmd ) ; pb . directory ( directory ) ; pb . redirectErrorStream ( true ) ; Process p = pb . start ( ) ; String s ; StringBuilder sb = new StringBuilder ( ) ; BufferedReader stdout = new BufferedReader ( new InputStreamReader ( p . getInputStream ( ) ) ) ; while ( ( s = stdout . readLine ( ) ) != null ) { logger . info ( s ) ; sb . append ( s ) ; sb . append ( '\n' ) ; } String sbs = sb . toString ( ) ; int exitValue = p . waitFor ( ) ; if ( exitValue != 0 ) throw new Exception ( errorMessage + " exit value " + exitValue + "  " + sbs ) ; return sbs ; }
run command cmd in separate process in directory
