List of usage examples for java.lang Process waitFor
public abstract int waitFor() throws InterruptedException;
From source file:com.uber.hoodie.cli.commands.SavepointsCommand.java
@CliCommand(value = "savepoint rollback", help = "Savepoint a commit") public String rollbackToSavepoint( @CliOption(key = { "savepoint" }, help = "Savepoint to rollback") final String commitTime, @CliOption(key = {//from w ww. ja va 2s .c om "sparkProperties" }, help = "Spark Properites File Path") final String sparkPropertiesPath) throws Exception { HoodieActiveTimeline activeTimeline = HoodieCLI.tableMetadata.getActiveTimeline(); HoodieTimeline timeline = activeTimeline.getCommitTimeline().filterCompletedInstants(); HoodieInstant commitInstant = new HoodieInstant(false, HoodieTimeline.COMMIT_ACTION, commitTime); if (!timeline.containsInstant(commitInstant)) { return "Commit " + commitTime + " not found in Commits " + timeline; } SparkLauncher sparkLauncher = SparkUtil.initLauncher(sparkPropertiesPath); sparkLauncher.addAppArgs(SparkMain.SparkCommand.ROLLBACK_TO_SAVEPOINT.toString(), commitTime, HoodieCLI.tableMetadata.getBasePath()); Process process = sparkLauncher.launch(); InputStreamConsumer.captureOutput(process); int exitCode = process.waitFor(); // Refresh the current refreshMetaClient(); if (exitCode != 0) { return "Savepoint " + commitTime + " failed to roll back"; } return "Savepoint " + commitTime + " rolled back"; }
From source file:com.orange.clara.cloud.servicedbdumper.acceptance.AcceptanceExternalTest.java
protected boolean isCfCliPluginAvailable() { Runtime rt = Runtime.getRuntime(); Process proc = null; try {/* w w w . j a v a 2 s . c om*/ proc = rt.exec(this.dbDumperCli()); proc.waitFor(); } catch (IOException | InterruptedException e) { return false; } int exitVal = proc.exitValue(); return exitVal == 0; }
From source file:klapersuite.prismanalysis.linux.PrismRunner.java
private int exitValueAfterTermination(Process process) { while (true) { try {/* w ww . j av a 2s .c o m*/ logger.debug("Process exit value: " + process.waitFor()); return process.exitValue(); } catch (InterruptedException e) { logger.debug("Prism execution wait interrupted"); } } }
From source file:AndroidUninstallStock.java
public static LinkedList<String> run(String... adb_and_args) throws IOException { Process pr = new ProcessBuilder(adb_and_args).redirectErrorStream(true).start(); BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream())); LinkedList<String> res = new LinkedList<String>(); String line;// w w w . ja v a2s . c om while ((line = buf.readLine()) != null) { if (!line.isEmpty()) { res.add(line); } } try { pr.waitFor(); } catch (InterruptedException e) { } return res; }
From source file:cu.uci.uengine.runner.impl.FileRunner.java
@Override public RunnerResult run(Runnable runnable, RunnerContext runnerContext) throws IOException, InterruptedException { String command = buildCommand(runnable.getLanguageName(), runnable.getRunnableFile().getAbsolutePath(), runnerContext.getTemporaryDirectory().getAbsolutePath()); log.debug("Running dataset " + runnerContext.getInputFile().getName()); String name = FilenameUtils.getBaseName(runnerContext.getInputFile().getName()); File outFile = new File(runnerContext.getTemporaryDirectory(), name + ".out"); File errFile = new File(runnerContext.getTemporaryDirectory(), name + ".err"); ProcessBuilder pb = buildProcessBuilder(runnable.getLimits(), runnable.getLanguageName(), runnerContext.getInputFile().getAbsolutePath(), outFile, errFile, command, String.valueOf(runnable.getId()), runnable.isTrusted()); Process process = pb.start(); process.waitFor(); if (process.exitValue() != 0) { byte[] processError = new byte[process.getErrorStream().available()]; process.getErrorStream().read(processError); return new RunnerResult(RunnerResult.Result.IE, FileUtils.readFileToString(errFile) + new String(processError)); }//from www.java2 s.c om // result,usertime,cputime,memory String[] results = IOUtils.toString(process.getInputStream()).split(","); // el resultado OK significa que no dio problema ejecutar // con libsandbox. Los demas resultados son errores internos // o resultados que no precisan que se siga ejecutando (TLE, // MLE, etc.) // En OK se debe seguir con el proximo juego de datos, los // demas resultados ya detienen la ejecucion. RunnerResult result = null; String resultCode = results[SandboxResults.RESULT]; switch (resultCode) { case "OK": result = new RunnerResult(RunnerResult.Result.OK, name, Long.valueOf(results[SandboxResults.USER_TIME]), Long.valueOf(results[SandboxResults.CPU_TIME]), Long.valueOf(results[SandboxResults.MEMORY]) * 1024); break; case "AT": result = new RunnerResult(RunnerResult.Result.RT); result.messageConcat(FileUtils.readFileToString(errFile)); break; case "TL": result = new RunnerResult(RunnerResult.Result.CTL); break; case "RF": case "ML": case "OL": case "RT": case "IE": case "BP": case "PD": result = new RunnerResult(RunnerResult.Result.valueOf(resultCode)); result.messageConcat(FileUtils.readFileToString(errFile)); break; } if (outFile.length() > runnable.getLimits().getMaxOutput()) { result = new RunnerResult(RunnerResult.Result.OL); } return result; }
From source file:com.intuit.tank.standalone.agent.StandaloneAgentStartup.java
public void startTest(final StandaloneAgentRequest request) { Thread t = new Thread(new Runnable() { public void run() { try { currentAvailability.setAvailabilityStatus(AgentAvailabilityStatus.DELEGATING); sendAvailability();//from ww w . ja v a 2 s . c o m LOG.info("Starting up: ControllerBaseUrl=" + controllerBase); URL url = new URL(controllerBase + SERVICE_RELATIVE_PATH + METHOD_SETTINGS); LOG.info("Starting up: making call to tank service url to get settings.xml " + url.toExternalForm()); InputStream settingsStream = url.openStream(); try { String settings = IOUtils.toString(settingsStream); FileUtils.writeStringToFile(new File("settings.xml"), settings); LOG.info("got settings file..."); } finally { IOUtils.closeQuietly(settingsStream); } url = new URL(controllerBase + SERVICE_RELATIVE_PATH + METHOD_SUPPORT); LOG.info("Making call to tank service url to get support files " + url.toExternalForm()); ZipInputStream zip = new ZipInputStream(url.openStream()); try { ZipEntry entry = zip.getNextEntry(); while (entry != null) { String name = entry.getName(); LOG.info("Got file from controller: " + name); File f = new File(name); FileOutputStream fout = FileUtils.openOutputStream(f); try { IOUtils.copy(zip, fout); } finally { IOUtils.closeQuietly(fout); } entry = zip.getNextEntry(); } } finally { IOUtils.closeQuietly(zip); } // now start the harness String cmd = API_HARNESS_COMMAND + " -http=" + controllerBase + " -jobId=" + request.getJobId() + " -stopBehavior=" + request.getStopBehavior(); LOG.info("Starting apiharness with command: " + cmd); currentAvailability.setAvailabilityStatus(AgentAvailabilityStatus.RUNNING_JOB); sendAvailability(); Process exec = Runtime.getRuntime().exec(cmd); exec.waitFor(); currentAvailability.setAvailabilityStatus(AgentAvailabilityStatus.AVAILABLE); sendAvailability(); // } catch (Exception e) { LOG.error("Error in AgentStartup " + e, e); currentAvailability.setAvailabilityStatus(AgentAvailabilityStatus.AVAILABLE); sendAvailability(); } } }); t.start(); }
From source file:algorithm.F5Steganography.java
private void encapsulate(String carrier, String payload, String output) throws IOException { try {/*from w w w .j ava 2s .co m*/ String[] args = new String[] { "java", "-jar", LIBRARY_DIRECTORY + "f5.jar", "e", "-e", payload, carrier, output }; Process process = Runtime.getRuntime().exec(args); process.waitFor(); InputStream inputStream = process.getInputStream(); byte b[] = new byte[inputStream.available()]; inputStream.read(b, 0, b.length); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:cn.dreampie.common.plugin.lesscss.compiler.NodeJsLessCssCompiler.java
private String compile(String input) throws LessException, IOException, InterruptedException { long start = System.currentTimeMillis(); File inputFile = File.createTempFile("lessc-input-", ".less"); FileOutputStream out = new FileOutputStream(inputFile); IOUtils.write(input, out);//from w w w. ja va 2s . c o m out.close(); File outputFile = File.createTempFile("lessc-output-", ".css"); File lesscJsFile = new File(tempDir, "lessc.js"); ProcessBuilder pb = new ProcessBuilder(nodeExecutablePath, lesscJsFile.getAbsolutePath(), inputFile.getAbsolutePath(), outputFile.getAbsolutePath(), String.valueOf(compress)); pb.redirectErrorStream(true); Process process = pb.start(); IOUtils.copy(process.getInputStream(), System.out); int exitStatus = process.waitFor(); FileInputStream in = new FileInputStream(outputFile); String result = IOUtils.toString(in); in.close(); if (!inputFile.delete()) { logger.warn("Could not delete temp file: " + inputFile.getAbsolutePath()); } if (!outputFile.delete()) { logger.warn("Could not delete temp file: " + outputFile.getAbsolutePath()); } if (exitStatus != 0) { throw new LessException(result, null); } logger.debug("Finished compilation of LESS source in " + (System.currentTimeMillis() - start) + " ms."); return result; }
From source file:com.frostwire.gui.updates.UpdateMediator.java
public void startUpdate() { GUIMediator.safeInvokeLater(new Runnable() { public void run() { File executableFile = getUpdateBinaryFile(); if (executableFile == null || latestMsg == null) { return; }//from w w w. j a v a 2s . c o m try { if (OSUtils.isWindows()) { String[] commands = new String[] { "CMD.EXE", "/C", executableFile.getAbsolutePath() }; ProcessBuilder pbuilder = new ProcessBuilder(commands); pbuilder.start(); } else if (OSUtils.isLinux() && OSUtils.isUbuntu()) { String[] commands = new String[] { "gdebi-gtk", executableFile.getAbsolutePath() }; ProcessBuilder pbuilder = new ProcessBuilder(commands); pbuilder.start(); } else if (OSUtils.isMacOSX()) { String[] mountCommand = new String[] { "hdiutil", "attach", executableFile.getAbsolutePath() }; String[] finderShowCommand = new String[] { "open", "/Volumes/" + FilenameUtils.getBaseName(executableFile.getName()) }; ProcessBuilder pbuilder = new ProcessBuilder(mountCommand); Process mountingProcess = pbuilder.start(); mountingProcess.waitFor(); pbuilder = new ProcessBuilder(finderShowCommand); pbuilder.start(); } GUIMediator.shutdown(); } catch (Throwable e) { LOG.error("Unable to launch new installer", e); } } }); }
From source file:com.smash.revolance.ui.materials.CmdlineHelper.java
public CmdlineHelper exec() throws InterruptedException, IOException { ProcessBuilder pb = new ProcessBuilder(); if (dir != null) { pb.directory(dir);//from w w w .j av a 2s . c o m } pb.command(cmd); pb.redirectError(ProcessBuilder.Redirect.to(err)); pb.redirectOutput(ProcessBuilder.Redirect.to(out)); pb.redirectInput(ProcessBuilder.Redirect.from(in)); System.out.println("Executing cmd: " + cmd[0] + " from dir: " + dir); System.out.println("Redirecting out to: " + out.getAbsolutePath()); System.out.println("Redirecting err to: " + err.getAbsolutePath()); Process process = pb.start(); if (sync) { process.waitFor(); } this.process = process; return this; }