List of usage examples for java.lang Process exitValue
public abstract int exitValue();
From source file:Main.java
public static int exeCmdSilence(String cmd) { int result = -1; try {/*from w w w .j a va 2 s . c o m*/ Process p = Runtime.getRuntime().exec(cmd); p.waitFor(); result = p.exitValue(); } catch (Exception e) { // TODO: handle exception } return result; }
From source file:Main.java
static boolean isProcessCompleted(Process process) { try {//from w ww . ja v a 2s . c om if (process == null) return true; process.exitValue(); return true; } catch (IllegalThreadStateException e) { // do nothing } return false; }
From source file:cu.uci.uengine.utils.FileUtils.java
public static boolean dos2unixFileFixer(String filePath) throws IOException, InterruptedException { // bash es muy sensible a los cambios de linea \r\n de Windows. Para // prevenir que esto cause Runtime Errors, es necesario convertirlos a // un sistema comprensible por ubuntu: \n normal en linux. El comando // dos2unix hace esto. // se lo dejamos a todos los codigos para evitar que algun otro lenguaje // tambien padezca de esto Properties langProps = new Properties(); langProps.load(ClassLoader.getSystemResourceAsStream("uengine.properties")); String dos2unixPath = langProps.getProperty("dos2unix.path"); ProcessBuilder pb = new ProcessBuilder(dos2unixPath, filePath); Process process = pb.start(); process.waitFor();//from ww w . j ava 2s. c o m return process.exitValue() == 0; }
From source file:org.polymap.p4.data.importer.raster.ExternalProgram.java
protected static boolean isRunning(Process process) { try {//from w w w . ja v a 2 s. co m process.exitValue(); return false; } catch (IllegalThreadStateException e) { return true; } }
From source file:org.apache.bsf.util.JavaUtils.java
public static boolean JDKcompile(String fileName, String classPath) { String option = (logger.isDebugEnabled()) ? "-g" : "-O"; String args[] = { "javac", option, "-classpath", classPath, fileName }; logger.debug("JavaEngine: Compiling " + fileName); logger.debug("JavaEngine: Classpath is " + classPath); try {/*from w w w . j av a 2 s . c om*/ Process p = java.lang.Runtime.getRuntime().exec(args); p.waitFor(); return (p.exitValue() != 0); } catch (IOException e) { logger.error("ERROR: IO exception during exec(javac).", e); } catch (SecurityException e) { logger.error("ERROR: Unable to create subprocess to exec(javac).", e); } catch (InterruptedException e) { logger.error("ERROR: Wait for exec(javac) was interrupted.", e); } return false; }
From source file:Main.java
/********* * Returns the exit code of the given process handle, or null if the process has not terminated. * * @param processToCheck/*from www .j av a 2 s . c o m*/ * the process. * @return the exit code, or null. */ public static Integer getProcessExitCode(final Process processToCheck) { if (processToCheck == null) { return null; } try { int val = processToCheck.exitValue(); return val; } catch (final Exception e) { return null; } }
From source file:ConsoleUtils.java
public static int execute(String command) throws InterruptedException, IOException { Process process = Runtime.getRuntime().exec(command); process.waitFor();//from w w w .j a v a 2 s.c o m return process.exitValue(); }
From source file:org.sonar.process.ProcessUtils.java
/** * Do not abuse to this method. It uses exceptions to get status. * @return false if process is null or terminated, else true. *//* ww w . ja va 2 s. c o m*/ public static boolean isAlive(@Nullable Process process) { boolean alive = false; if (process != null) { try { process.exitValue(); } catch (IllegalThreadStateException ignored) { alive = true; } } return alive; }
From source file:org.phenotips.textanalysis.internal.BiolarkFileUtils.java
/** * Builds project in target directory, by executing 'make clean && make'. * * @param target directory containing makefile * @param runtime the Runtime instance of this application * @throws BuildException if the build failed * @throws NotDirectoryException if target is not a directory */// w ww .ja v a 2s . com public static void make(File target, Runtime runtime) throws BuildException, NotDirectoryException { if (target.isDirectory()) { try { Process p = Runtime.getRuntime().exec("make -B", null, target); p.waitFor(); if (p.exitValue() != 0) { IOUtils.copy(p.getErrorStream(), System.out); throw new BuildException("Build failed in " + target.getAbsolutePath()); } } catch (IOException e) { throw new BuildException(e.getMessage()); } catch (InterruptedException e) { throw new BuildException(e.getMessage()); } } else { throw new NotDirectoryException(target.getPath()); } }
From source file:org.astrojournal.utilities.DesktopBrowse.java
/** * Browse an URI using a platform specific browser. * //from w w w .j a v a2 s .co m * @param command * the platform specific command to execute * @param uri * the URI to browser * @return true if the command succeeded, false otherwise. */ private static boolean browseByPlatform(String command, URI uri) { String[] browseCommand = new String[] { command, uri.toString() }; log.debug("Trying to run " + browseCommand[0] + " " + browseCommand[1]); try { Process p = Runtime.getRuntime().exec(browseCommand); if (p == null || p.exitValue() == 0) { log.debug("The command '" + browseCommand[0] + " " + browseCommand[1] + "' did not start or terminated immediately."); return false; } log.debug("The command '" + browseCommand[0] + " " + browseCommand[1] + "' crashed for some reason."); } catch (IllegalThreadStateException e) { log.debug("The command '" + browseCommand[0] + " " + browseCommand[1] + "' is running!"); return true; } catch (IOException e) { // Let's not report the stack trace as we are still trying. log.debug(e); } return false; }