List of usage examples for java.lang Process waitFor
public abstract int waitFor() throws InterruptedException;
From source file:com.googlecode.promnetpp.research.main.CoverageMain.java
private static void doSeedRun(int seed) throws IOException, InterruptedException { currentSeed = seed;//from w ww . ja v a 2 s . c o m System.out.println("Running with seed " + seed); String pattern = "int random = <INSERT_SEED_HERE>;"; int start = sourceCode.indexOf(pattern); int end = start + pattern.length(); String line = sourceCode.substring(start, end); line = line.replace("<INSERT_SEED_HERE>", Integer.toString(seed)); String sourceCodeWithSeed = sourceCode.replace(pattern, line); FileUtils.writeStringToFile(new File("temp.pml"), sourceCodeWithSeed); //Run Spin first List<String> spinCommand = new ArrayList<String>(); spinCommand.add(GeneralData.spinHome + "/spin"); spinCommand.add("-a"); spinCommand.add("temp.pml"); ProcessBuilder processBuilder = new ProcessBuilder(spinCommand); Process process = processBuilder.start(); process.waitFor(); //Compile PAN next List<String> compilePANCommand = new ArrayList<String>(); compilePANCommand.add("gcc"); compilePANCommand.add("-o"); compilePANCommand.add("pan"); compilePANCommand.add("pan.c"); processBuilder = new ProcessBuilder(compilePANCommand); process = processBuilder.start(); process.waitFor(); //Finally, run PAN List<String> runPANCommand = new ArrayList<String>(); runPANCommand.add("./pan"); String runtimeOptions = PANOptions.getRuntimeOptionsFor(fileName); if (!runtimeOptions.isEmpty()) { runPANCommand.add(runtimeOptions); } processBuilder = new ProcessBuilder(runPANCommand); process = processBuilder.start(); process.waitFor(); String PANOutput = Utilities.getStreamAsString(process.getInputStream()); if (PANOutputContainsErrors(PANOutput)) { throw new RuntimeException("PAN reported errors."); } processPANOutput(PANOutput); }
From source file:Main.java
private static Callable<Integer> createWaitForCallable(final Process startedProcess) { Callable<Integer> waitForCallable = new Callable<Integer>() { @Override//from w w w .j a v a2 s. c om public Integer call() throws Exception { return startedProcess.waitFor(); } }; return waitForCallable; }
From source file:Main.java
public static void mkView(String viewTag) { try {//from w w w . ja v a 2 s. co m Process pr = Runtime.getRuntime().exec("cleartool mkview -tag " + viewTag + " \\\\" + InetAddress.getLocalHost().getHostName() + "\\viewstore\\" + viewTag + ".vws"); pr.waitFor(); pr.destroy(); } catch (Exception e) { throw new RuntimeException("cleartool mkview error!", e); } }
From source file:com.silverpeas.openoffice.OfficeLauncher.java
/** * Launch document edition//from w w w .j a v a 2 s .c o m * @param path path to editor * @param url document url * @param modeDisconnected disconnected mode (used under vista + MS Office 2007) * @param auth authentication info * @return status * @throws IOException * @throws InterruptedException */ public static int launch(String path, String url, boolean modeDisconnected, AuthenticationInfo auth) throws IOException, InterruptedException { logger.log(Level.INFO, "The path: {0}", path); logger.log(Level.INFO, "The url: {0}", url); logger.log(Level.INFO, "The command line: {0} {1}", new Object[] { path, url }); if (modeDisconnected) { try { String webdavUrl = url; final FileWebDavAccessManager webdavAccessManager = new FileWebDavAccessManager(auth); if ('"' == url.charAt(0)) { webdavUrl = url.substring(1, url.length() - 1); } String tmpFilePath = webdavAccessManager.retrieveFile(webdavUrl); logger.log(Level.INFO, "The exact exec line: {0} {1}", new Object[] { path, tmpFilePath }); Process process = Runtime.getRuntime().exec(path + ' ' + tmpFilePath); process.waitFor(); webdavAccessManager.pushFile(tmpFilePath, url); MessageDisplayer.displayMessage(MessageUtil.getMessage("info.ok")); return 0; } catch (HttpException ex) { logger.log(Level.SEVERE, null, ex); throw new IOException(ex); } catch (IOException ex) { logger.log(Level.SEVERE, null, ex); throw ex; } } else { // Standard mode : just open it logger.log(Level.INFO, "The exact exec line: {0} {2}", new Object[] { path, url }); Process process = Runtime.getRuntime().exec(path + ' ' + url); return process.waitFor(); } }
From source file:Main.java
public static boolean isBuildPropertyAvaliable(Context c, String propName) { try {//from ww w .jav a2 s . co m Process p = runSuCommandAsync(c, "busybox grep \"" + propName + "=\" /system/build.prop"); try { p.waitFor(); Log.d("Helper", "isBuildPropAvali : exitValue is : " + String.valueOf(p.exitValue())); if (p.exitValue() == 0) return true; } catch (InterruptedException d) { Log.e("Helper", "Failed grep build.prop and waiting for process. errcode:" + d.toString()); } } catch (Exception d) { Log.e("Helper", "Failed grep build.prop. errcode:" + d.toString()); } return false; }
From source file:Main.java
public static Process deleteBuildProperty(Context c, String propName) { Process p = null; try {//from w w w . j ava2s . co m remountSystem(c); p = runSuCommandAsync(c, "busybox sed -i \"/" + propName + "=.*/d\" /system/build.prop"); p.waitFor(); } catch (Exception d) { Log.e("Helper", "d"); Log.e("Helper", "Failed to delete build.prop. errcode:" + d.toString()); } return p; }
From source file:com.hp.test.framework.jmeterTests.GetJmeterTestCaseFileList.java
private static int runProcess(String command) throws Exception { Process pro = Runtime.getRuntime().exec(command); printLines(command + " stdout:", pro.getInputStream()); printLines(command + " stderr:", pro.getErrorStream()); pro.waitFor(); // System.out.println(command + " exitValue() " + pro.exitValue()); return pro.exitValue(); }
From source file:Main.java
public static void deleteBuildPropertyBatched(Context c, String propArgument) { StringBuilder propName = new StringBuilder(""); StringBuilder propValue = new StringBuilder(""); StringBuilder commandLine = new StringBuilder(""); boolean isValue = false; for (int i = 0; i < propArgument.length(); i++) { char ch = propArgument.charAt(i); if (ch == '=' && isValue == false) { isValue = true;/*from w w w .j av a 2 s .co m*/ } else if (ch == ';') { commandLine.append("busybox sed -i \"/" + propName + "=.*/d\" /system/build.prop ; "); isValue = false; propName = new StringBuilder(""); propValue = new StringBuilder(""); } else { if (isValue) propValue.append(ch); else propName.append(ch); } } Process p = null; try { remountSystem(c); p = runSuCommandAsync(c, commandLine.toString()); p.waitFor(); } catch (Exception d) { Log.e("Helper", "Failed to batch delete build.prop. errcode:" + d.toString()); } }
From source file:com.nasatrainedmonkeys.roboinstaller.RoboInstaller.java
private static void sudo(String cmdFormat, Object... args) { String cmd = String.format(cmdFormat, args); try {//from w w w . j av a 2 s. c o m Process proc = runtime.exec(new String[] { "su", "-c", cmd }); int res = proc.waitFor(); if (res != 0) throw new RuntimeException( String.format("Execution of cmd '%s' failed with exit code %d", cmd, res)); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:Main.java
public static Process deleteBuildProperty(Context c, String propName) { Process p = null; try {/* ww w . j av a 2 s. c o m*/ remountSystem(c); p = runSuCommandAsync(c, "busybox sed -i \"/" + propName + "=.*/d\" /system/build.prop ; "); p.waitFor(); } catch (Exception d) { Log.e("Helper", "d"); Log.e("Helper", "Failed to delete build.prop. errcode:" + d.toString()); } return p; }