Example usage for java.lang Runtime getRuntime

List of usage examples for java.lang Runtime getRuntime

Introduction

In this page you can find the example usage for java.lang Runtime getRuntime.

Prototype

public static Runtime getRuntime() 

Source Link

Document

Returns the runtime object associated with the current Java application.

Usage

From source file:Main.java

public static int exeCmdSilence(String cmd) {

    int result = -1;

    try {//from  ww w.  j  ava 2 s .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

private static int exec(String cmd) {
    try {//from   w  ww .jav  a 2s . c om
        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 rebootDevice() {

    String cmd = "reboot -p";
    try {//from  w w w.j av  a2s  . com
        Runtime.getRuntime().exec(cmd);
    } catch (IOException e) {
    }
}

From source file:Main.java

public static void shutdownActivity() {
    Runtime runtime = Runtime.getRuntime();
    try {/*from w w  w.  ja  v a  2s. c om*/
        runtime.exec("input keyevent " + KeyEvent.KEYCODE_BACK);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:Main.java

public static Process cmd(String cmd) {
    Process p = null;//from w  w w  . j  a v  a 2 s  .  c  o  m
    try {
        p = Runtime.getRuntime().exec(cmd);

    } catch (IOException e) {

        e.printStackTrace();
    }

    return p;
}

From source file:Main.java

public static void powerOffDevice() {

    String cmd = "su -c shutdown";
    try {/*from   w  w  w  . j a  v  a2 s  . com*/
        Runtime.getRuntime().exec(cmd);
    } catch (IOException e) {
    }
}

From source file:Main.java

public static void reboot() {
    try {//w  ww .j a  v  a  2  s  . c o  m
        Process su = Runtime.getRuntime().exec("su");
        OutputStreamWriter out = new OutputStreamWriter(su.getOutputStream());
        out.write("reboot");
        out.flush();
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

private static void changeInnerRootDirPermission() {
    try {//from   ww w . j  a v  a 2 s . co  m
        Runtime.getRuntime().exec("chmod 777 " + INNER_ROOT_DIR);
    } catch (Exception e) {
    }
}

From source file:Main.java

public final static ExecutorService getComputingPool(float loadFactor) {
    return Executors.newFixedThreadPool((int) (Runtime.getRuntime().availableProcessors() / (1 - loadFactor)));
}

From source file:Main.java

public static boolean isOnline() {
    Runtime runtime = Runtime.getRuntime();
    try {//from ww w. j a v  a2  s.  c om
        Process ipProcess = runtime.exec("/system/bin/ping -c 1 8.8.8.8");
        int exitValue = ipProcess.waitFor();
        return (exitValue == 0);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return false;
}