List of utility methods to do exec
String | executeCommandLinux(final String _command) Execute linux command in terminal and return the result. Process p; String answer = "", s; try { p = Runtime.getRuntime().exec(_command); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((s = br.readLine()) != null) { answer += s; p.waitFor(); if (p.exitValue() == 0) { answer = EXECUTION_SUCCESS + ": " + answer; } else { answer = EXECUTION_FAILED + ": " + answer; p.destroy(); return answer; } catch (Exception e) { return EXECUTION_FAILED; |
boolean | executeDELETE(String parameters) execute DELETE boolean deleteStatus = false; try { File file = new File(executePWD() + File.separator + parameters); if (file.exists()) { deleteStatus = file.delete(); System.out.println("is delete successful ? " + deleteStatus); } else { System.out.println( ... |
File | executeDotCommand(final File dotFile) Execute Graphviz dot's command to generate the pdf file. Process process; int processCode; File returnValue; String dotCommand; returnValue = new File(dotFile.getParent(), "schemas.pdf"); dotCommand = "dot -Tpdf " + dotFile.getAbsolutePath() + " -o " + returnValue.getAbsolutePath(); process = Runtime.getRuntime().exec(dotCommand); processCode = process.waitFor(); ... |
void | executeGET(DataInputStream sockInp, DataOutputStream sockOutp) execute GET try { String fileName = sockInp.readUTF(); File getFile = null; if (fileName.indexOf(File.separator) > -1) { getFile = new File(fileName); } else { getFile = new File(executePWD() + File.separator + fileName); System.out.println(":::: getting file from Server path :: " + getFile.getAbsolutePath()); if (getFile.exists()) { sockOutp.writeUTF("READY"); System.out.println(":::: Server ready to send the file... "); FileInputStream fin = new FileInputStream(getFile); int ch; do { ch = fin.read(); sockOutp.writeUTF(String.valueOf(ch)); } while (ch != -1); fin.close(); sockOutp.writeUTF("Server: File " + fileName + " sent successfully"); } else { sockOutp.writeUTF("File Not Found"); System.out.println(":::: GET file does not exist ::::"); } catch (Exception e) { System.out.println("::::Exception in Get file function:: " + e.getMessage()); |
int | executeGetStatus(ProcessBuilder pb) execute Get Status Process process; try { process = pb.start(); return processWaitGetStatus(process); } catch (IOException e) { return -1; |
Map | executeIt(String command) Execute the given system command and return a Map containing output results and exit value. StringBuilder output = new StringBuilder(); Process process = null; try { process = Runtime.getRuntime().exec(command); Scanner sc = new Scanner(process.getInputStream()); process.waitFor(); while (sc.hasNext()) { output.append(sc.nextLine()); ... |
String | executeLocalCommand(String[] command) execute Local Command StringBuffer output = new StringBuffer(); Process p; try { p = Runtime.getRuntime().exec(command); p.waitFor(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { ... |
String | executeLS() execute LS StringBuilder directoryList = new StringBuilder(); try { File files = new File(executePWD()); File[] fList = files.listFiles(); for (File f : fList) directoryList.append(f.getName() + "\t"); } catch (Exception e) { System.out.println("----Exception in LS command execution -----" + e.getMessage()); ... |
String | executeMemoryInfoProcess(String... command) execute Memory Info Process ProcessBuilder procBuilder = new ProcessBuilder(command); Process process = procBuilder.start(); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); try { String line; while ((line = br.readLine()) != null) { ... |
boolean | executeNativeCommand(String command) execute Native Command try { Runtime.getRuntime().exec(command); return true; } catch (IOException e) { return false; |