List of utility methods to do exec
Process | exec(String[] args) exec ProcessBuilder processBuilder = new ProcessBuilder(args); return processBuilder.start(); |
String | execAdbCmd(String cmd) exec Adb Cmd String result = ""; Runtime runtime = Runtime.getRuntime(); Process process = null; BufferedReader bufferedReader = null; try { process = runtime.exec(cmd); bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream(), "utf-8")); String buffer; ... |
String | execAndGetOutput(ProcessBuilder builder) exec And Get Output Process process = builder.redirectErrorStream(true).start(); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); try { return reader.readLine(); } finally { reader.close(); |
int | execCmd(String cmd) exec Cmd Process p = Runtime.getRuntime().exec(cmd); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; while ((line = in.readLine()) != null) { System.out.println(line); return 0; |
String | execCmd(String cmd) execute a command in the shell of the OS Process p = Runtime.getRuntime().exec(cmd); InputStream is = p.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); String line = " a"; while ((line = br.readLine()) != null) { pw.println(line); ... |
String | execCmd(String cmd, File where) exec Cmd Process p = Runtime.getRuntime().exec(cmd, null, where); Scanner s = new Scanner(p.getInputStream()); String ret = ""; s.useDelimiter("\\A"); if (s.hasNext()) ret = s.next(); s.close(); return ret; ... |
String | execCmd(String command) exec Cmd BufferedReader br = null; StringBuffer stringBuffer = new StringBuffer(); try { Process p = Runtime.getRuntime().exec(command); br = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; while ((line = br.readLine()) != null) { if ("".equals(line.trim())) ... |
String | execCmdWindows(String cmd) exec Cmd Windows java.util.Scanner s = new java.util.Scanner( Runtime.getRuntime().exec(String.format("cmd /c %s", cmd)).getInputStream()).useDelimiter("\\A"); return s.hasNext() ? s.next() : ""; |
int | execCommand(String cmd) exec Command return execCommand(cmd, null, true, true);
|
String | execCommand(String command) exec Command String result = null; String newLine = System.getProperty("line.separator"); try { Process p = Runtime.getRuntime().exec(command); p.waitFor(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); StringBuilder response = new StringBuilder(); String line = reader.readLine(); ... |