List of usage examples for java.lang Process waitFor
public abstract int waitFor() throws InterruptedException;
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(); System.out.println("Done."); }
From source file:Main.java
public static void main(String[] args) throws Exception { Process process = Runtime.getRuntime().exec("ls -al"); process.waitFor(); int exitValue = process.exitValue(); System.out.println("exitValue = " + exitValue); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { System.out.println(line); }/*from w ww . java 2 s . c o m*/ }
From source file:ProcessBuilderDemo.java
public static void main(String argv[]) throws InterruptedException, IOException { List<String> command = new ArrayList<String>(); command.add("notepad"); command.add("foo.txt"); ProcessBuilder builder = new ProcessBuilder(command); Map<String, String> environ = builder.environment(); environ.put("PATH", "/windows;/windows/system32;/winnt"); builder.directory(new File(System.getProperty("user.home"))); final Process godot = builder.start(); godot.waitFor(); System.out.println("Program terminated!"); return;/*from w ww . jav a2 s . c o m*/ }
From source file:ExecDemoFini.java
public static void main(String args[]) { Runtime r = Runtime.getRuntime(); Process p = null; try {// w w w. j a v a2s . c om p = r.exec("notepad"); p.waitFor(); } catch (Exception e) { System.out.println("Error executing notepad."); } System.out.println("Notepad returned " + p.exitValue()); }
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 ww w . j av a 2 s. c o m*/ } 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) { try {/* ww w. j ava2 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:com.frederikam.fredboat.bootloader.Bootloader.java
public static void main(String[] args) throws IOException, InterruptedException { OUTER: while (true) { InputStream is = new FileInputStream(new File("./bootloader.json")); Scanner scanner = new Scanner(is); JSONObject json = new JSONObject(scanner.useDelimiter("\\A").next()); scanner.close();/*from www . j a v a 2 s.c o m*/ command = json.getJSONArray("command"); jarName = json.getString("jarName"); Process process = boot(); process.waitFor(); System.out.println("[BOOTLOADER] Bot exited with code " + process.exitValue()); switch (process.exitValue()) { case ExitCodes.EXIT_CODE_UPDATE: System.out.println("[BOOTLOADER] Now updating..."); update(); break; case 130: case ExitCodes.EXIT_CODE_NORMAL: System.out.println("[BOOTLOADER] Now shutting down..."); break OUTER; //SIGINT received or clean exit default: System.out.println("[BOOTLOADER] Now restarting.."); break; } } }
From source file:MainClass.java
public static void main(String args[]) { Runtime r = Runtime.getRuntime(); Process p = null; String cmd[] = { "notepad", "/java/src/java/lang/Runtime.java" }; try {/*from www .j ava 2 s . com*/ p = r.exec(cmd); p.waitFor(); } catch (Exception e) { System.out.println("error executing " + cmd[0]); } System.out.println(cmd[0] + " returned " + p.exitValue()); }
From source file:ExecDemoSort2.java
public static void main(String[] av) { // A Runtime object has methods for dealing with the OS Runtime r = Runtime.getRuntime(); // A process object tracks one external running process Process p; try {//from w w w . jav a2 s. c om // file contains unsorted data p = r.exec("sort sortdemo.txt"); p.waitFor(); } catch (java.io.IOException e) { System.err.println("I/O error: " + e); } catch (InterruptedException e) { // nothing to do } }
From source file:ExecDemoPartial.java
public static void main(String argv[]) throws IOException { BufferedReader is; // reader for output of process String line;/*from w ww.j a v a 2s . c om*/ final Process p = Runtime.getRuntime().exec(PROGRAM); Thread waiter = new Thread() { public void run() { try { p.waitFor(); } catch (InterruptedException ex) { // OK, just quit this thread. return; } System.out.println("Program terminated!"); done = true; } }; waiter.start(); // getInputStream gives an Input stream connected to // the process p's standard output (and vice versa). We use // that to construct a BufferedReader so we can readLine() it. is = new BufferedReader(new InputStreamReader(p.getInputStream())); while (!done && ((line = is.readLine()) != null)) System.out.println(line); return; }