List of utility methods to do exec
boolean | execute2(final String appPath) execute try { Runtime runtime = Runtime.getRuntime(); runtime.exec(appPath); } catch (IOException | SecurityException | NullPointerException | IllegalArgumentException e) { e.printStackTrace(); return false; return true; ... |
void | executeAndWait(String command) execute And Wait try { Process proc = Runtime.getRuntime().exec(command); int returnCode = proc.waitFor(); if (returnCode != 0) { throw new IllegalStateException( "Could not execute " + command + ", process returned " + returnCode); } catch (InterruptedException e) { ... |
void | executeApplication(String filePath) execute Application ProcessBuilder processBuilder = new ProcessBuilder(); processBuilder.command("java", "-jar", filePath); processBuilder.start(); |
boolean | executeBashScriptWithParams(ArrayList execute Bash Script With Params try { ProcessBuilder pb = new ProcessBuilder(script); final Process process = pb.start(); process.waitFor(); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String result = br.readLine(); ... |
void | executeBatFile(String batFile) execute Bat File Runtime runtime = Runtime.getRuntime(); runtime.exec(batFile); |
String | executeCD(String dirPath) execute CD String retStatus = null; try { if (dirPath.equals("..")) { File curr = new File(executePWD()); if (curr.getAbsoluteFile().getParent() != null) System.setProperty(ROOT, curr.getAbsoluteFile().getParent()); else System.out.println("::: Reached root directory :::" + ROOT); ... |
String | executeCmdCommand(String command) execute Cmd Command System.out.println("Execute " + command); ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c", command); Process p = builder.start(); BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream())); StringBuilder result = new StringBuilder(); String line; while (true) { line = r.readLine(); ... |
BufferedReader | executeCmdForReader(String cmd) execute Cmd For Reader Process pro = Runtime.getRuntime().exec(cmd); BufferedReader bufReader = new BufferedReader(new InputStreamReader(pro.getInputStream(), "UTF-8")); return bufReader; |
Process | executeComand(String[] comand) execute Comand return Runtime.getRuntime().exec(comand);
|
String | executeCommand(final ProcessBuilder pb) execute Command final StringBuffer output = new StringBuffer(); Process p; try { p = pb.start(); final BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { output.append(line + "\n"); ... |