Example usage for java.lang Process waitFor

List of usage examples for java.lang Process waitFor

Introduction

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

Prototype

public abstract int waitFor() throws InterruptedException;

Source Link

Document

Causes the current thread to wait, if necessary, until the process represented by this Process object has terminated.

Usage

From source file:Main.java

public static int runSuCommandNoScriptWrapper(Context context, String command)
        throws IOException, InterruptedException {
    String[] args = new String[] { "su", "-c", command };
    Process proc = Runtime.getRuntime().exec(args);
    return proc.waitFor();
}

From source file:Main.java

private static int exec(String cmd) {
    try {//from  w w  w. j  a  va  2s  .  c o m
        Runtime runtime = Runtime.getRuntime();
        Process p = runtime.exec(cmd);
        return p.waitFor();
    } catch (IOException e) {
        e.printStackTrace();
        return -1;
    } catch (InterruptedException e) {
        e.printStackTrace();
        return -1;
    }
}

From source file:Main.java

public static void chmod(String mode, String path) {
    try {//  w  w  w  .  j a v a 2 s.  c  om
        String command = "chmod " + mode + " " + path;
        Runtime runtime = Runtime.getRuntime();
        Process process = runtime.exec(command);
        process.waitFor();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static boolean execCmd(String cmd) {
    try {//from w  w  w .  j a v  a2 s . co m
        Process p = Runtime.getRuntime().exec(cmd);
        p.waitFor();
    } catch (Exception e) {
        return false;
    }
    return true;
}

From source file:Main.java

public static int exeCmdSilence(String cmd) {

    int result = -1;

    try {//ww w  .java  2s.c  om
        Process p = Runtime.getRuntime().exec(cmd);
        p.waitFor();
        result = p.exitValue();
    } catch (Exception e) {
        // TODO: handle exception
    }
    return result;
}

From source file:Main.java

public static void chmod(String permission, String path) {
    try {/*from   w  w w  . j  a  v  a 2s  .c  om*/
        String command = "chmod " + permission + " " + path;
        Runtime runtime = Runtime.getRuntime();
        java.lang.Process process = runtime.exec(command);
        process.waitFor();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void startView(String viewTag) {
    try {/*from  w w w.j a  v  a  2 s.c  o m*/
        Process p1 = Runtime.getRuntime().exec("cleartool startview " + viewTag);
        p1.waitFor();
        p1.destroy();
    } catch (Exception e) {
        throw new RuntimeException("cleartool startview error!", e);
    }
}

From source file:Main.java

public static void clearResource(String targetDir) {
    String[] str = { "rm", "-r", targetDir };

    try {/*from   w w  w.ja v a 2 s.  c o  m*/
        Process ps = Runtime.getRuntime().exec(str);
        try {
            ps.waitFor();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void rmView(String viewTag) {
    try {//from w  ww  .  j  a v  a2s .c om
        Process pr = Runtime.getRuntime().exec("cleartool rmview -tag ".concat(viewTag));
        pr.waitFor();
        pr.destroy();
    } catch (Exception e) {
        throw new RuntimeException("cleartool rmview error!", e);
    }
}

From source file:Main.java

/**
 * Executes single ping and return/*  w ww  .  ja va 2  s . co m*/
 * @param ip - address to ping
 * @return true - ping was successful
 */
public static boolean ping(String ip) {
    Runtime runtime = Runtime.getRuntime();

    try {
        Process process = runtime.exec("/system/bin/ping -c 1 " + ip);
        return process.waitFor() == 0;

    } catch (Exception ignore) {
        Log.e(TAG, "Error while", ignore);
    }

    return false;
}