List of usage examples for java.lang Process waitFor
public abstract int waitFor() throws InterruptedException;
From source file:fi.jumi.test.AppRunner.java
private static void kill(Process process) { process.destroy();/* ww w . j av a 2s.c o m*/ try { process.waitFor(); } catch (InterruptedException e) { e.printStackTrace(); Thread.currentThread().interrupt(); } }
From source file:Main.java
public static boolean runWithRoot(String command) { int result = -1; Process process = null; DataOutputStream os = null;/*from w w w . j a va 2 s .com*/ try { process = Runtime.getRuntime().exec("su"); os = new DataOutputStream(process.getOutputStream()); os.writeBytes(command + "\n"); os.writeBytes("exit\n"); os.flush(); result = process.waitFor(); } catch (Exception e) { return false; } finally { if (process != null) { process.destroy(); } } return result == 1; }
From source file:Main.java
public static void RunRootCmd(String cmd) { try {/*from w w w .j a v a 2 s . c om*/ // // run our command using 'su' to gain root // Process process = Runtime.getRuntime().exec("su"); DataOutputStream outputStream = new DataOutputStream(process.getOutputStream()); outputStream.writeBytes(cmd + "\n"); outputStream.flush(); outputStream.writeBytes("exit\n"); outputStream.flush(); process.waitFor(); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:Main.java
public static Process writeBuildProperty(Context c, String propName, String value) { Process p = null; try {/*from w w w.j a v a 2 s.co m*/ remountSystem(c); p = runSuCommandAsync(c, "echo " + propName + "=" + value + " >> /system/build.prop"); Log.d("Helper", "echo " + propName + "=" + value + " >> /system/build.prop"); p.waitFor(); } catch (Exception d) { Log.e("Helper", "Failed to write build.prop. errcode:" + d.toString()); } return p; }
From source file:Main.java
public static boolean runRootCommand(Context context, String command) { Process process = null; DataOutputStream os = null;/*from w w w.j a v a 2 s . c o m*/ try { process = Runtime.getRuntime().exec("su"); os = new DataOutputStream(process.getOutputStream()); os.writeBytes(command + "\n"); os.writeBytes("exit\n"); os.flush(); process.waitFor(); } catch (Exception e) { Log.d("*** DEBUG ***", "Error - " + e.getMessage()); return false; } finally { try { if (os != null) { os.close(); } process.destroy(); } catch (Exception e) { } } return true; }
From source file:Main.java
public static boolean tempRunRootCommand(Context context, String command) { Process process = null; DataOutputStream os = null;//from w w w .j a v a2 s . c om try { process = Runtime.getRuntime().exec("su1"); os = new DataOutputStream(process.getOutputStream()); os.writeBytes(command + "\n"); os.writeBytes("exit\n"); os.flush(); process.waitFor(); } catch (Exception e) { Log.d("*** DEBUG ***", "Error - " + e.getMessage()); return false; } finally { try { if (os != null) { os.close(); } process.destroy(); } catch (Exception e) { } } return true; }
From source file:fr.inria.oak.paxquery.xparser.client.XClient.java
private static void printDOTFile(String filePath, String dotString) { String filePathDot = filePath; String filePathPNG = filePath; if (filePathDot.startsWith("file://")) { filePathDot = filePathDot.substring("file://".length()); filePathPNG = filePathPNG.substring("file://".length()); }/* ww w.jav a 2s . c o m*/ /* * int extensionIndex = filePathDot.lastIndexOf("."); if(extensionIndex > -1) { filePathDot = * filePathDot.subSequence(0, extensionIndex) + "-pact.dot"; filePathPNG = * filePathPNG.subSequence(0, extensionIndex) + "-pact.png"; } else { filePathDot = filePathDot * + "-pact.dot"; filePathPNG = filePathPNG + "-pact.png"; } */ if (filePath.endsWith("/") == true) { filePathDot = filePathDot + "xoutput-pact.dot"; filePathPNG = filePathPNG + "xoutput-pact.png"; } else { filePathDot = filePathDot + "/xoutput-pact.dot"; filePathPNG = filePathPNG + "/xoutput-pact.png"; } try { // print the dot file FileWriter writer = new FileWriter(filePathDot, false); writer.write(dotString); writer.close(); Runtime r = Runtime.getRuntime(); String com = new String("dot -Tpng " + filePathDot + " -o " + filePathPNG); Process p = r.exec(com); p.waitFor(); // System.out.println("PACT plan drawn."); } catch (IOException ioe) { System.out.println("Error with pact file: " + ioe.getMessage()); } catch (InterruptedException ie) { System.out.println("Error with pact file: " + ie.getMessage()); } }
From source file:com.liferay.blade.samples.integration.test.utils.BladeCLIUtil.java
public static String execute(File workingDir, String... bladeArgs) throws Exception { String bladeCLIJarPath = getLatestBladeCLIJar(); List<String> command = new ArrayList<>(); command.add("java"); command.add("-jar"); command.add(bladeCLIJarPath);//from w w w . j a v a 2 s .co m for (String arg : bladeArgs) { command.add(arg); } Process process = new ProcessBuilder(command.toArray(new String[0])).directory(workingDir).start(); process.waitFor(); InputStream stream = process.getInputStream(); String output = new String(IO.read(stream)); InputStream errorStream = process.getErrorStream(); List<String> errorList = new ArrayList<>(); String stringStream = null; if (errorStream != null) { stringStream = new String(IO.read(errorStream)); errorList.add(stringStream); } List<String> filteredErrorList = new ArrayList<>(); for (String string : errorList) { String exclusion = "(.*setlocale.*)"; Pattern p = Pattern.compile(exclusion, Pattern.DOTALL); Matcher m = p.matcher(string); while (m.find()) { filteredErrorList.add(string); } if (string.contains("Picked up JAVA_TOOL_OPTIONS:")) { filteredErrorList.add(string); } } errorList.removeAll(filteredErrorList); Assert.assertTrue(errorList.toString(), errorList.size() <= 1); if (errorList.size() == 1) { Assert.assertTrue(errorList.get(0), errorList.get(0).isEmpty()); } return output; }
From source file:Main.java
public static Process writeBuildProperty(Context c, String propName, String value) { Process p = null; try {/*w ww .jav a 2 s. c o m*/ remountSystem(c); p = runSuCommandAsync(c, "echo " + propName + "=" + value + " >> /system/build.prop ; "); Log.d("Helper", "echo " + propName + "=" + value + " >> /system/build.prop ; "); p.waitFor(); } catch (Exception d) { Log.e("Helper", "Failed to write build.prop. errcode:" + d.toString()); } return p; }
From source file:javadepchecker.Main.java
private static Collection<String> getPackageJars(String pkg) { ArrayList<String> jars = new ArrayList<String>(); try {/*from w ww. ja va 2s . c o m*/ Process p = Runtime.getRuntime().exec("java-config -p " + pkg); p.waitFor(); BufferedReader in; in = new BufferedReader(new InputStreamReader(p.getInputStream())); String output = in.readLine(); if (output != null/* package somehow missing*/ && !output.trim().equals("")) { for (String jar : output.split(":")) { jars.add(jar); } } } catch (InterruptedException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } return jars; }