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 { Runtime r = Runtime.getRuntime(); String[] nargs = { "sh", "-c", "for i in 1 2 3; do echo $i; done" }; Process p = r.exec(nargs);/*from w ww . j a va 2 s . com*/ BufferedReader is = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while ((line = is.readLine()) != null) System.out.println(line); }
From source file:Main.java
public static void main(String[] args) { try {/*from w ww. j a v a2 s . c o m*/ // create a new process Process p = Runtime.getRuntime().exec("notepad.exe"); // get the error stream of the process and print it InputStream error = p.getErrorStream(); for (int i = 0; i < error.available(); i++) { System.out.println(error.read()); } // wait for 10 seconds and then destroy the process Thread.sleep(10000); p.destroy(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String argv[]) throws Exception { String line;//from ww w . ja v a 2 s . com Process p = Runtime.getRuntime().exec("psql -U username -d dbname -h serverhost -f scripfile.sql"); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((line = input.readLine()) != null) { System.out.println(line); } input.close(); }
From source file:Main.java
public static void main(String[] args) { try {//from w w w . j av a 2 s . c o m // create a new process Process p = Runtime.getRuntime().exec("notepad.exe"); // get the input stream of the process and print it InputStream in = p.getInputStream(); for (int i = 0; i < in.available(); i++) { System.out.println(in.read()); } // wait for 10 seconds and then destroy the process Thread.sleep(10000); p.destroy(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {/*from ww w .ja va 2 s .c o m*/ // create a new process System.out.println("Creating Process..."); Process p = Runtime.getRuntime().exec("notepad.exe"); // wait 10 seconds System.out.println("Waiting..."); Thread.sleep(10000); // kill the process p.destroy(); System.out.println("Process destroyed."); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {// ww w. ja v a 2s .co m // create a new process Process p = Runtime.getRuntime().exec("notepad.exe"); // get the output stream OutputStream out = p.getOutputStream(); // close the output stream System.out.println("Closing the output stream..."); out.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Run1.java
public static void main(String[] args) throws java.io.IOException { if (args.length != 1) { System.err.println("usage: java Run pathname"); return;//from w w w . j a va 2 s. com } Process p = Runtime.getRuntime().exec(args[0]); try { System.out.println("Exit status = " + p.waitFor()); } catch (InterruptedException e) { } }
From source file:Main.java
public static void main(String[] args) throws Exception { String fileName = "c:\\temp\\test.bmp"; String[] commands = { "cmd.exe", "/c", "start", "\"DummyTitle\"", "\"" + fileName + "\"" }; Process p = Runtime.getRuntime().exec(commands); p.waitFor();// w w w. j av a 2 s .co m System.out.println("Done."); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] commands = new String[] { "grep", "hello world", "/tmp/f.txt" }; commands = new String[] { "grep", "hello world", "c:/f.txt" }; Process child = Runtime.getRuntime().exec(commands); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] commands = new String[] { "grep", "hello world", "/tmp/f.txt" }; commands = new String[] { "grep", "hello world", "c:\\f.txt" }; Process child = Runtime.getRuntime().exec(commands); }