List of utility methods to do exec
Process | exeCmdByOs(String cmd) exe Cmd By Os Process process = null; Runtime runtime = Runtime.getRuntime(); String osName = System.getProperty("os.name"); if (osName.toLowerCase().startsWith("win")) { process = runtime.exec((new String[] { "cmd", "/C", cmd })); } else { process = runtime.exec((new String[] { "sh", "-c", cmd })); return process; |
String | execName() exec Name return isWindows() ? "rake.bat" : "rake"; |
int | execPrint(final boolean out, final String... command) Executes the command, optionally copying output to standard output. final ProcessBuilder builder = new ProcessBuilder(command); builder.redirectErrorStream(true); final Process p = builder.start(); final InputStream is = p.getInputStream(); int c; while ((c = is.read()) >= 0) if (out) { System.out.write(c); ... |
boolean | execProcess(String process) exec Process try { String command = "cmd /C start /wait " + process; Process p = Runtime.getRuntime().exec(command); p.waitFor(); } catch (IOException | InterruptedException e) { logError(e); return false; return true; |
int | execProcess(String[] cmdline, final long timeout) execProcess Process process = Runtime.getRuntime().exec(cmdline); final Thread thread = Thread.currentThread(); Thread waitTimeout = new Thread() { public void run() { try { Thread.sleep(timeout); thread.interrupt(); } catch (InterruptedException ignore) { ... |
String | Execption2Strings(boolean rep, Throwable... execptions) Execption Strings StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); for (Throwable e : execptions) { e.printStackTrace(pw); if (rep) { return sw.toString().replaceAll("\r\n|\n\r|\r|\n", "<br/>\n"); return sw.toString(); |
Process | execScript(File shellScriptFile, String[] scriptCommand, PrintWriter execLog) execScript is a function that executes shell scripts Process child2 = Runtime.getRuntime().exec(scriptCommand); String line; BufferedReader in = new BufferedReader(new InputStreamReader(child2.getInputStream())); while ((line = in.readLine()) != null) { execLog.println(line); execLog.flush(); BufferedReader errorReader = new BufferedReader(new InputStreamReader(child2.getErrorStream())); ... |
Process | execShell(String cmd) exec Shell return Runtime.getRuntime().exec(getShellArgs(cmd));
|
String | execShell(String shell) exec Shell Runtime rt = Runtime.getRuntime();
Process process = rt.exec(shell);
return getOutputMsg(process);
|
void | execSudoCommand(final String _sudoCmd, final String _pw) exec Sudo Command String[] cmd = { "/bin/bash", "-c", "echo " + _pw + "| sudo -S " + _sudoCmd }; try { Runtime.getRuntime().exec(cmd); } catch (IOException e) { e.printStackTrace(); |