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 void main(String[] args) {

    // start tracing for instructions
    Runtime runTime = Runtime.getRuntime();
    runTime.traceMethodCalls(true);/*from w w  w .ja  v  a2s  . com*/
}

From source file:Main.java

public static void main(String[] args) {

    // print the maximum memory

    Runtime runTime = Runtime.getRuntime();

    System.out.println(runTime.maxMemory());

}

From source file:Main.java

public static void main(String[] args) {

    // check the number of processors available
    Runtime runTime = Runtime.getRuntime();
    System.out.println(runTime.availableProcessors());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String[] cmd = { "/bin/sh", "-c", "ls > hello" };
    Runtime.getRuntime().exec(cmd);

}

From source file:MainClass.java

public static void main(String args[]) {
    Runtime r = Runtime.getRuntime();
    Process p = null;//w w  w .  j a v a 2 s.c  o m
    String cmd[] = { "notepad", "/java/src/java/lang/Runtime.java" };
    try {
        p = r.exec(cmd);
    } catch (Exception e) {
        System.out.println("error executing " + cmd[0]);
    }
}

From source file:Main.java

public static void main(String[] args) {
    try {//from   w  w  w .  java  2 s . c  o m
        // create a new process
        Process p = Runtime.getRuntime().exec("notepad.exe");

        p.destroy();

        System.out.println(p.exitValue());

    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {

    // get the current runtime assosiated with this process
    Runtime run = Runtime.getRuntime();

    // print the current free memory for this runtime
    System.out.println("" + run.freeMemory());
}

From source file:Main.java

public static void main(String[] args) {
    try {//from  ww w.j  a va2 s  . c  om
        // create a new process
        Process p = Runtime.getRuntime().exec("notepad.exe");

        // cause this process to stop until process p is terminated
        p.waitFor();

        // when you manually close notepad.exe this program will continue
        System.out.println("Waiting over.");

    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String command = "cat";
    Process child = Runtime.getRuntime().exec(command);
    OutputStream out = child.getOutputStream();
    out.write("some text".getBytes());
    out.close();//from  w  ww  .j  a  va 2 s  .  c om
}

From source file:MainClass.java

public static void main(String args[]) {
    Runtime r = Runtime.getRuntime();
    Process p = null;/*from w  w w .  j  a  va 2s. c o  m*/
    String cmd[] = { "notepad", "/java/src/java/lang/Runtime.java" };
    try {
        p = r.exec(cmd);
        p.waitFor();
    } catch (Exception e) {
        System.out.println("error executing " + cmd[0]);
    }
    System.out.println(cmd[0] + " returned " + p.exitValue());
}