Example usage for java.lang Process exitValue

List of usage examples for java.lang Process exitValue

Introduction

In this page you can find the example usage for java.lang Process exitValue.

Prototype

public abstract int exitValue();

Source Link

Document

Returns the exit value for the process.

Usage

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();/*from  w  w w  .  ja  v  a 2  s  . c o  m*/
    //  System.out.println(command + " exitValue() " + pro.exitValue());
    return pro.exitValue();
}

From source file:Main.java

public static int execRootCmdSilent(String cmd) {

    int result = -1;
    DataOutputStream dos = null;//w ww. ja v a2 s  . c o m

    try {
        Process p = Runtime.getRuntime().exec("su");
        dos = new DataOutputStream(p.getOutputStream());

        dos.writeBytes(cmd + "\n");
        dos.flush();
        dos.writeBytes("exit\n");
        dos.flush();
        p.waitFor();
        result = p.exitValue();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (dos != null) {
            try {
                dos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return result;
}

From source file:com.twitter.bazel.checkstyle.PythonCheckstyle.java

private static void runLinter(List<String> command) throws IOException {
    LOG.finer("checkstyle command: " + command);

    ProcessBuilder processBuilder = new ProcessBuilder(command);
    processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
    processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
    Process pylint = processBuilder.start();

    try {/*from   ww  w.  j a  v a  2s.co m*/
        pylint.waitFor();
    } catch (InterruptedException e) {
        throw new RuntimeException("python checkstyle command was interrupted: " + command, e);
    }

    if (pylint.exitValue() == 30) {
        LOG.warning("python checkstyle detected bad styles.");
        // SUPPRESS CHECKSTYLE RegexpSinglelineJava
        System.exit(1);
    }

    if (pylint.exitValue() != 0) {
        throw new RuntimeException("python checkstyle command failed with status " + pylint.exitValue());
    }
}

From source file:com.twitter.bazel.checkstyle.CppCheckstyle.java

private static void runLinter(List<String> command) throws IOException {
    LOG.fine("checkstyle command: " + command);

    ProcessBuilder processBuilder = new ProcessBuilder(command);
    processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
    processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
    Process cpplint = processBuilder.start();

    try {//from ww  w  .ja  v  a  2 s  . c om
        cpplint.waitFor();
    } catch (InterruptedException e) {
        throw new RuntimeException("cpp checkstyle command was interrupted: " + command, e);
    }

    if (cpplint.exitValue() == 1) {
        LOG.warning("cpp checkstyle detected bad styles.");
        // SUPPRESS CHECKSTYLE RegexpSinglelineJava
        System.exit(1);
    }

    if (cpplint.exitValue() != 0) {
        throw new RuntimeException("cpp checkstyle command failed with status " + cpplint.exitValue());
    }
}

From source file:com.adguard.compiler.PackageUtils.java

private static void execute(String... commands) throws IOException, InterruptedException {
    ProcessBuilder pb = new ProcessBuilder(commands);
    Process p = pb.start();
    BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;//from   w w w .  j  ava 2 s.c om
    while ((line = reader.readLine()) != null) {
        log.debug(line);
    }
    p.waitFor();
    if (p.exitValue() != 0) {
        reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
        while ((line = reader.readLine()) != null) {
            log.error(line);
        }
        throw new IOException("Command " + ArrayUtils.toString(commands) + " not success");
    }
}

From source file:edu.ku.brc.af.ui.ProcessListUtil.java

/**
 * @param processId//from   ww  w . j  a v a  2  s. c o m
 * @return
 */
public static boolean killProcess(final int processId) {
    String cmd;
    if (UIHelper.isWindows()) {
        cmd = "taskkill /PID " + processId;
    } else {
        cmd = "kill " + processId;
    }

    try {
        Process process = Runtime.getRuntime().exec(cmd);
        process.waitFor();
        return process.exitValue() == 0;
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    return false;
}

From source file:org.openspaces.test.client.executor.Executor.java

/**
 * @return <code>true</code> if supplied process is still alive, otherwise <code>false</code>
 *///from w  w w .  j  av  a 2 s  .  com
static boolean isProcessAlive(Process process) {
    try {
        process.exitValue();
        return false;
    } catch (IllegalThreadStateException e) {
        return true;
    }
}

From source file:net.dv8tion.discord.Yui.java

private static void relaunchInUTF8() throws InterruptedException, UnsupportedEncodingException {
    System.out.println("BotLauncher: We are not running in UTF-8 mode! This is a problem!");
    System.out.println("BotLauncher: Relaunching in UTF-8 mode using -Dfile.encoding=UTF-8");

    String[] command = new String[] { "java", "-Dfile.encoding=UTF-8", "-jar",
            Yui.getThisJarFile().getAbsolutePath() };

    //Relaunches the bot using UTF-8 mode.
    ProcessBuilder processBuilder = new ProcessBuilder(command);
    processBuilder.inheritIO(); //Tells the new process to use the same command line as this one.
    try {/*from w w  w. j a va 2  s.c  om*/
        Process process = processBuilder.start();
        process.waitFor(); //We wait here until the actual bot stops. We do this so that we can keep using the same command line.
        System.exit(process.exitValue());
    } catch (IOException e) {
        if (e.getMessage().contains("\"java\"")) {
            System.out.println(
                    "BotLauncher: There was an error relaunching the bot. We couldn't find Java to launch with.");
            System.out.println("BotLauncher: Attempted to relaunch using the command:\n   "
                    + StringUtils.join(command, " ", 0, command.length));
            System.out.println(
                    "BotLauncher: Make sure that you have Java properly set in your Operating System's PATH variable.");
            System.out.println("BotLauncher: Stopping here.");
        } else {
            e.printStackTrace();
        }
    }
}

From source file:org.apache.sling.maven.slingstart.run.LauncherCallable.java

private static boolean isAlive(Process process) {
    try {/*from ww w . j  a  va 2 s.  com*/
        process.exitValue();
        return false;
    } catch (IllegalThreadStateException e) {
        return true;
    }
}

From source file:citibob.licensor.MakeLauncher.java

static void exec(File dir, String... cmds) throws IOException, InterruptedException {
    Process proc = Runtime.getRuntime().exec(cmds, null, dir);
    InputStream in = proc.getInputStream();
    int c;//from   ww  w .ja  v a 2 s. c  om
    while ((c = in.read()) >= 0)
        System.out.write(c);
    proc.waitFor();
    System.out.println("---> exit value = " + proc.exitValue());
}