List of usage examples for java.lang Runtime getRuntime
public static Runtime getRuntime()
From source file:MainClass.java
public static void main(String[] args) throws Exception { Object f = new Object() { public void finalize() { System.out.println("Running finalize()"); }//from w w w.ja v a 2 s .co m }; Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { System.out.println("Running Shutdown Hook"); } }); f = null; System.gc(); System.out.println("Calling System.exit()"); System.exit(0); }
From source file:ExecShellArgs.java
public static void main(String[] args) throws IOException { Runtime r = Runtime.getRuntime(); String[] nargs = { "sh", "-c", "for i in 1 2 3; do echo $i; done" }; Process p = r.exec(nargs);/*from www .ja va2 s .c o m*/ BufferedReader is = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while ((line = is.readLine()) != null) System.out.println(line); }
From source file:Message.java
public static void main(String[] args) { try {//from ww w . j a va2s .c o m // register Message as shutdown hook Runtime runTime = Runtime.getRuntime(); runTime.addShutdownHook(new Message()); } catch (Exception e) { e.printStackTrace(); } }
From source file:ExecDemoRm.java
public static void main(String[] args) throws IOException { for (int i = 0; i < 10; i++) { new File("/tmp/ww" + i).createNewFile(); }//from w ww . ja va2 s . co m Runtime.getRuntime().exec("ls -l /tmp/ww? > /tmp/report"); Runtime.getRuntime().exec("rm -f /tmp/ww?"); }
From source file:Run2.java
public static void main(String[] args) throws java.io.IOException { if (args.length != 1) { System.err.println("usage: java Run pathname"); return;//from ww w. j a v a2 s . c o m } Process p = Runtime.getRuntime().exec(args[0]); InputStream is = p.getInputStream(); int b; while ((b = is.read()) != -1) System.out.print((char) b); try { System.out.println("Exit status = " + p.waitFor()); } catch (InterruptedException e) { } }
From source file:Main.java
public static void main(String args[]) throws IOException { Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec(args); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line;/*from w ww .j ava 2 s . c o m*/ System.out.printf("Output of running %s is:", Arrays.toString(args)); while ((line = br.readLine()) != null) { System.out.println(line); } }
From source file:Main.java
public static void main(String[] args) throws InterruptedException { Main task = new Main(); int threads = Runtime.getRuntime().availableProcessors(); ExecutorService pool = Executors.newFixedThreadPool(threads); for (int i = 0; i < threads; i++) { pool.submit(task);/*from w w w . j a v a 2s. c om*/ } pool.awaitTermination(120, TimeUnit.SECONDS); }
From source file:Main.java
public static void main(String[] args) { try {/*from w w w.j av a 2s. com*/ String[] envArray = new String[2]; envArray[0] = ""; envArray[1] = ""; // create a process and execute notepad.exe and currect environment Runtime runTime = Runtime.getRuntime(); Process process = runTime.exec("notepad.exe", envArray); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { InputStream fileInputStream;//from w ww . j a va 2 s . co m try { fileInputStream = new FileInputStream("c:/a.txy"); Runtime runTime = Runtime.getRuntime(); runTime.getLocalizedInputStream(fileInputStream); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:Message.java
public static void main(String[] args) { try {//from w w w .ja v a2 s. c o m Message p = new Message(); // register Message as shutdown hook Runtime runTime = Runtime.getRuntime(); runTime.addShutdownHook(p); // remove the hook runTime.removeShutdownHook(p); System.out.println("Program is closing..."); } catch (Exception e) { e.printStackTrace(); } }