List of usage examples for java.lang Process exitValue
public abstract int exitValue();
From source file:org.jboss.tools.openshift.internal.ui.preferences.OpenShiftPreferencePage.java
private String findOCLocation() { String location = null;//w w w. jav a 2s . co m if (SystemUtils.IS_OS_WINDOWS) { String[] paths = StringUtils.split(System.getenv("PATH"), ";"); for (String path : paths) { Collection<File> files = FileUtils.listFiles(new File(path), new IOFileFilter() { @Override public boolean accept(File file) { return ocBinary.getName().equals(file.getName()); } @Override public boolean accept(File dir, String name) { return ocBinary.getName().equals(name); } }, null); if (files.size() > 0) { location = files.iterator().next().toString(); break; } } } else { String path = ThreadUtils.runWithTimeout(WHICH_CMD_TIMEOUT, new Callable<String>() { @Override public String call() throws Exception { Process process = null; try { process = new ProcessBuilder("which", ocBinary.getName()).start(); process.waitFor(); if (process.exitValue() == WHICH_CMD_SUCCESS) { return IOUtils.toString(process.getInputStream()); } ; } catch (IOException e) { OpenShiftUIActivator.getDefault().getLogger().logError("Could not run 'which' command", e); } finally { if (process != null) { process.destroy(); } } return null; } }); if (!StringUtils.isEmpty(path)) { location = path; } } return StringUtils.trim(location); }
From source file:org.jboss.qa.jenkins.test.executor.utils.MavenCli.java
public void run() throws Exception { final List<String> cmd = new ArrayList<>(); // Maven//from w w w . j av a 2s . co m if (OSDetector.isWindows()) { // TODO(mbasovni): Not yet tested! cmd.add("cmd"); cmd.add("/c"); cmd.add(mavenHome + "/bin/mvn.bat"); } else { cmd.add("/bin/bash"); cmd.add(mavenHome + "/bin/mvn"); } // Maven opts if (xms != null) { mavenOpts.add("-Xms" + xms); } if (xmx != null) { mavenOpts.add("-Xmx" + xmx); } if (maxPermSize != null) { mavenOpts.add("-XX:MaxPermSize=" + maxPermSize); } // Path to POM file cmd.add("-f"); cmd.add(pom.getAbsolutePath()); cmd.addAll(goals); // Profiles if (!profiles.isEmpty()) { cmd.add("-P" + StringUtils.join(profiles, ",")); } // Projects if (!projects.isEmpty()) { cmd.add("-pl"); cmd.add(StringUtils.join(projects, ",")); } // If project list is specified, also build projects required by the list if (alsoMake) { cmd.add("-am"); } // Only fail the build afterwards; allow all non-impacted builds to continue if (failAtEnd) { cmd.add("-fae"); } // System properties for (Map.Entry<String, String> entry : sysProps.entrySet()) { cmd.add(String.format("-D%s=%s", entry.getKey(), entry.getValue())); } if (params != null) { cmd.addAll(params); } final ProcessBuilder processBuilder = new ProcessBuilder(cmd); processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT); processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT); processBuilder.environment().put("JAVA_HOME", javaHome.getAbsolutePath()); processBuilder.environment().put("M2_HOME", mavenHome.getAbsolutePath()); processBuilder.environment().put("MAVEN_OTPS", StringUtils.join(mavenOpts, " ")); log.debug("==========="); log.debug("Process arguments: " + cmd.toString()); log.debug("JAVA_HOME={}", processBuilder.environment().get("JAVA_HOME")); log.debug("M2_HOME={}", processBuilder.environment().get("M2_HOME")); log.debug("MAVEN_OTPS={}", processBuilder.environment().get("MAVEN_OTPS")); final Process process = processBuilder.start(); process.waitFor(); if (process.exitValue() != 0) { log.error("Maven execution failed with exit code: " + process.exitValue()); } }
From source file:com.gordoni.opal.ScenarioSet.java
public void subprocess(String cmd, String prefix, String... args) throws IOException, InterruptedException { String real_cwd = System.getProperty("user.dir"); List<String> arguments = new ArrayList<String>(Arrays.asList(args)); arguments.add(0, real_cwd + "/" + cmd); ProcessBuilder pb = new ProcessBuilder(arguments); Map<String, String> env = pb.environment(); env.put("OPAL_FILE_PREFIX", cwd + "/" + prefix); pb.redirectError(Redirect.INHERIT);/*from w w w . jav a2 s.co m*/ Process p = pb.start(); InputStream stdout = p.getInputStream(); byte buf[] = new byte[8192]; while (stdout.read(buf) != -1) { } p.waitFor(); assert (p.exitValue() == 0); }
From source file:org.fcrepo.importexport.integration.ExecutableJarIT.java
@Test public void testJarSanity() throws IOException, InterruptedException { // Run the executable jar with no arguments final Process process = startJarProcess(); // Verify it ran assertTrue("Process did not exit before timeout!", process.waitFor(TIMEOUT_SECONDS, TimeUnit.SECONDS)); assertEquals("Did not exit with success status!", 0, process.exitValue()); }
From source file:org.springframework.util.exec.Execute.java
protected void waitFor(Process process) { try {/*from w w w . ja va 2 s. c o m*/ process.waitFor(); setExitValue(process.exitValue()); } catch (InterruptedException e) { log.info("waitFor() interrupted "); Thread.currentThread().interrupt(); } }
From source file:io.hops.hopsworks.common.dao.tensorflow.config.TensorBoardProcessMgr.java
/** * Check to see if the process is running and is a TensorBoard started by tensorboard.sh * @param pid/*from www . j a v a2 s . c o m*/ * @return */ @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public int ping(BigInteger pid) { String prog = settings.getHopsworksDomainDir() + "/bin/tensorboard.sh"; int exitValue = 1; String[] command = { "/usr/bin/sudo", prog, "ping", pid.toString() }; LOGGER.log(Level.INFO, Arrays.toString(command)); ProcessBuilder pb = new ProcessBuilder(command); try { Process process = pb.start(); process.waitFor(20l, TimeUnit.SECONDS); exitValue = process.exitValue(); } catch (IOException | InterruptedException ex) { LOGGER.log(Level.SEVERE, "Problem pinging: {0}", ex.toString()); } return exitValue; }
From source file:io.hops.hopsworks.common.dao.tensorflow.config.TensorBoardProcessMgr.java
/** * Kill the TensorBoard process//from w w w . j ava 2 s .co m * @param pid * @return */ @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public int killTensorBoard(BigInteger pid) { String prog = settings.getHopsworksDomainDir() + "/bin/tensorboard.sh"; int exitValue; String[] command = { "/usr/bin/sudo", prog, "kill", pid.toString() }; LOGGER.log(Level.INFO, Arrays.toString(command)); ProcessBuilder pb = new ProcessBuilder(command); try { Process process = pb.start(); process.waitFor(20l, TimeUnit.SECONDS); exitValue = process.exitValue(); } catch (IOException | InterruptedException ex) { exitValue = 2; LOGGER.log(Level.SEVERE, "Failed to kill TensorBoard", ex); } return exitValue; }
From source file:io.hops.hopsworks.common.dao.tensorflow.config.TensorBoardProcessMgr.java
/** * Kill the TensorBoard process//from w w w. j av a 2 s.c o m * @param tb * @return */ @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public int killTensorBoard(TensorBoard tb) throws ServiceException { String prog = settings.getHopsworksDomainDir() + "/bin/tensorboard.sh"; int exitValue; String[] command = { "/usr/bin/sudo", prog, "kill", tb.getPid().toString() }; LOGGER.log(Level.INFO, Arrays.toString(command)); ProcessBuilder pb = new ProcessBuilder(command); try { Process process = pb.start(); process.waitFor(20l, TimeUnit.SECONDS); exitValue = process.exitValue(); cleanupLocalTBDir(tb); } catch (IOException | InterruptedException ex) { exitValue = 2; LOGGER.log(Level.SEVERE, "Failed to kill TensorBoard", ex); } return exitValue; }
From source file:jeplus.EPlusWinTools.java
public static String runJavaProgram(final String dir, final String jar, final String[] cmdline) { List<String> command = new ArrayList<>(); command.add("java"); command.add("-jar"); command.add(dir + (dir.endsWith(File.separator) ? "" : File.separator) + jar); command.addAll(Arrays.asList(cmdline)); ProcessBuilder builder = new ProcessBuilder(command); builder.directory(new File(dir)); builder.redirectErrorStream(true);// ww w .j a va 2 s. c o m try { Process proc = builder.start(); // int ExitValue = proc.waitFor(); StringBuilder buf = new StringBuilder(); try (BufferedReader ins = new BufferedReader(new InputStreamReader(proc.getInputStream()))) { String res = ins.readLine(); while (res != null) { buf.append(res); res = ins.readLine(); } } if (proc.exitValue() != 0) { return "Error: " + buf.toString(); } return buf.toString(); } catch (IOException ex) { logger.error("Cannot run Java program.", ex); } return "Error: failed to run the specified Java program."; }
From source file:com.orange.clara.cloud.servicedbdumper.dbdumper.core.CoreDumper.java
private void runDump(DatabaseDriver databaseDriver, String fileName) throws IOException, InterruptedException, RunProcessException { String[] commandLine = databaseDriver.getDumpCommandLine(); int i = 1;// w w w. j ava 2s . c o m while (true) { Process p = this.runCommandLine(commandLine); try { this.filer.store(p.getInputStream(), fileName); } catch (IOException e) { } catch (Exception e) { if (p.isAlive()) { p.destroy(); } throw e; } p.waitFor(); if (p.exitValue() == 0) { break; } if (i >= this.dbCommandRetry) { this.filer.delete(fileName); throw new RunProcessException("\nError during process (exit code is " + p.exitValue() + "): "); } logger.warn("Retry {}/{}: fail to dump data for file {}.", i, dbCommandRetry, fileName); Thread.sleep(10000); i++; } }