@Test public void cmd() throws IOException, InterruptedException { String initCmd = "E:\\gradle\\gradle-4.6\\bin\\gradle.bat propertiesInit"; String str = ShellUtil.cmd(initCmd, null, "E:/codes/test"); System.out.println(str); }
public static String cmd(String cmd, String[] envp, String dir) throws IOException, InterruptedException { Path path = Paths.get(dir); if (!Files.exists(path)) { Files.createDirectories(path); } Process process = Runtime.getRuntime().exec(cmd, envp, new File(dir)); InputStream is = process.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); process.waitFor(); StringBuffer stringBuffer = new StringBuffer(); String str; while ((str = reader.readLine()) != null) { stringBuffer.append(str).append("\r\n"); } return stringBuffer.toString(); }
ShellUtil { public static String cmd(String cmd, String[] envp, String dir) throws IOException, InterruptedException { Path path = Paths.get(dir); if (!Files.exists(path)) { Files.createDirectories(path); } Process process = Runtime.getRuntime().exec(cmd, envp, new File(dir)); InputStream is = process.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); process.waitFor(); StringBuffer stringBuffer = new StringBuffer(); String str; while ((str = reader.readLine()) != null) { stringBuffer.append(str).append("\r\n"); } return stringBuffer.toString(); } }
ShellUtil { public static String cmd(String cmd, String[] envp, String dir) throws IOException, InterruptedException { Path path = Paths.get(dir); if (!Files.exists(path)) { Files.createDirectories(path); } Process process = Runtime.getRuntime().exec(cmd, envp, new File(dir)); InputStream is = process.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); process.waitFor(); StringBuffer stringBuffer = new StringBuffer(); String str; while ((str = reader.readLine()) != null) { stringBuffer.append(str).append("\r\n"); } return stringBuffer.toString(); }  }
ShellUtil { public static String cmd(String cmd, String[] envp, String dir) throws IOException, InterruptedException { Path path = Paths.get(dir); if (!Files.exists(path)) { Files.createDirectories(path); } Process process = Runtime.getRuntime().exec(cmd, envp, new File(dir)); InputStream is = process.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); process.waitFor(); StringBuffer stringBuffer = new StringBuffer(); String str; while ((str = reader.readLine()) != null) { stringBuffer.append(str).append("\r\n"); } return stringBuffer.toString(); }  static String cmd(String cmd, String[] envp, String dir); }
ShellUtil { public static String cmd(String cmd, String[] envp, String dir) throws IOException, InterruptedException { Path path = Paths.get(dir); if (!Files.exists(path)) { Files.createDirectories(path); } Process process = Runtime.getRuntime().exec(cmd, envp, new File(dir)); InputStream is = process.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); process.waitFor(); StringBuffer stringBuffer = new StringBuffer(); String str; while ((str = reader.readLine()) != null) { stringBuffer.append(str).append("\r\n"); } return stringBuffer.toString(); }  static String cmd(String cmd, String[] envp, String dir);  }