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:hudson.slaves.CommandLauncher.java

private static void reportProcessTerminated(Process proc, TaskListener listener) {
    try {//from w  w  w .j ava 2  s . c  o  m
        int exitCode = proc.exitValue();
        listener.error("Process terminated with exit code " + exitCode);
    } catch (IllegalThreadStateException e) {
        // hasn't terminated yet
    }
}

From source file:net.floodlightcontroller.queuepusher.QueuePusherSwitchMapper.java

/**
 * Runs the given command// ww  w.  ja  v a  2  s  .c  om
 * 
 * @param cmd Command to execute
 * @return 0: (int)exit code 1: (string)stdout 2: (string)stderr
 */

private static Object[] eval(String cmd) {

    Object[] rsp = new Object[3];
    Runtime rt = Runtime.getRuntime();
    Process proc = null;

    try {
        proc = rt.exec(cmd);
        proc.waitFor();
        rsp[0] = proc.exitValue();
    } catch (InterruptedException e) {
        rsp[0] = 1;
    } catch (IOException e) {
        rsp[0] = 1;
    } finally {
        if (proc == null) {
            rsp[0] = 1;
        } else {

            try {

                BufferedReader stdout = new BufferedReader(new InputStreamReader(proc.getInputStream()));
                BufferedReader stderr = new BufferedReader(new InputStreamReader(proc.getErrorStream()));

                String temp;
                StringBuilder sb = new StringBuilder();
                while ((temp = stdout.readLine()) != null) {
                    sb.append(temp);
                }

                rsp[1] = sb.toString();
                sb = new StringBuilder();
                while ((temp = stderr.readLine()) != null) {
                    sb.append(temp);
                }

                rsp[2] = sb.toString();

            } catch (IOException e) {
                rsp[0] = 1;
            }

        }
    }

    return rsp;

}

From source file:org.openqa.selenium.server.browserlaunchers.AsyncExecute.java

/** Is this process still running ? */
public static boolean isAlive(Process p) {
    try {/*from   w  ww. ja  v a2  s .  co  m*/
        p.exitValue();
    } catch (IllegalThreadStateException e) {
        return true;
    }
    return false;
}

From source file:com.miz.mizuu.SearchForNetworkShares.java

public static boolean isReachableByPing(String host) {
    try {//  w  w  w  .ja  v  a  2 s .  c  om
        Process myProcess = Runtime.getRuntime().exec("ping -c 1 " + host);
        myProcess.waitFor();

        if (myProcess.exitValue() == 0)
            return true;
    } catch (Exception e) {
    }

    return false;
}

From source file:abs.backend.erlang.ErlangBackend.java

public static void compile(Model m, File destDir, boolean verbose)
        throws IOException, InterruptedException, InternalBackendException {
    if (verbose)//from w  ww . j  av a 2s .c  o m
        System.out.println("Generating Erlang code...");

    // check erlang version number
    Process versionCheck = Runtime.getRuntime().exec(new String[] { "erl", "-eval",
            "io:fwrite(\"~s\n\", [erlang:system_info(otp_release)]), halt().", "-noshell" });
    versionCheck.waitFor();
    BufferedReader ir = new BufferedReader(new InputStreamReader(versionCheck.getInputStream()));
    int version = Integer.parseInt(ir.readLine());
    if (version < minVersion) {
        String message = "ABS requires at least erlang version " + Integer.toString(minVersion)
                + ", installed version is " + Integer.toString(version);
        throw new InternalBackendException(message);
    }
    ErlApp erlApp = new ErlApp(destDir);
    m.generateErlangCode(erlApp);
    erlApp.close();
    String[] rebarProgram = new String[] { "escript", "../bin/rebar", "compile" };
    Process p = Runtime.getRuntime().exec(rebarProgram, null, new File(destDir, "absmodel"));
    if (verbose)
        IOUtils.copy(p.getInputStream(), System.out);
    p.waitFor();
    if (p.exitValue() != 0) {
        String message = "Compilation of generated erlang code failed with exit value " + p.exitValue();
        if (!verbose)
            message = message + "\n  (use -v for detailed compiler output)";
        throw new InternalBackendException(message);
        // TODO: consider removing the generated code here.  For now,
        // let's leave it in place for diagnosis.
    } else {
        if (verbose) {
            System.out.println();
            System.out.println("Finished.  \"gen/erl/run\" to start the model.");
            System.out.println("          (\"gen/erl/run --help\" for more options)");
        }
    }
}

From source file:eu.vital.vitalcep.cep.CepProcess.java

public static Boolean static_stopCEP(int PID, String cepFolder, String fileName)
        throws FileNotFoundException, IOException {

    String cmd = "kill -9 " + Integer.toString(PID);

    try {//from  ww  w .java  2 s  .  c  o m
        Process pr = Runtime.getRuntime().exec(cmd);
        if (pr.exitValue() == 0) {
            PID = -1;
            try {
                File file = new File(cepFolder//+"/"+dolceFile
                        + "/" + fileName + "_dolce");
                file.delete();
            } catch (Exception e) {
            }
        }
    } catch (IOException e) {
        return false;
    }

    return true;

}

From source file:brooklyn.util.io.FileUtil.java

public static void moveDir(File srcDir, File destDir) throws IOException, InterruptedException {
    if (!Os.isMicrosoftWindows()) {
        String cmd = "mv '" + srcDir.getAbsolutePath() + "' '" + destDir.getAbsolutePath() + "'";
        Process proc = Runtime.getRuntime().exec(cmd);
        proc.waitFor();//  w  w w . ja va  2  s  .co m
        if (proc.exitValue() == 0)
            return;
    }

    FileUtils.moveDirectory(srcDir, destDir);
}

From source file:brooklyn.util.io.FileUtil.java

public static void copyDir(File srcDir, File destDir) throws IOException, InterruptedException {
    if (!Os.isMicrosoftWindows()) {
        String cmd = "cp -R '" + srcDir.getAbsolutePath() + "' '" + destDir.getAbsolutePath() + "'";
        Process proc = Runtime.getRuntime().exec(cmd);
        proc.waitFor();//from ww  w  .  ja v a  2  s  . c o m
        if (proc.exitValue() == 0)
            return;
    }

    FileUtils.copyDirectory(srcDir, destDir);
}

From source file:org.springframework.cloud.deployer.spi.local.AbstractLocalDeployerSupport.java

protected static boolean isAlive(Process process) {
    try {//  ww w . j av  a2 s .  c o m
        process.exitValue();
        return false;
    } catch (IllegalThreadStateException e) {
        return true;
    }
}

From source file:Main.java

public static boolean isBuildPropertyAvaliable(Context c, String propName) {
    try {//from  w  ww .  j  ava2 s  . c  om
        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;
}