Avviare un processo da java
Problema
Avviare il programma /usr/bin/program.
Soluzione
01 try {
02 final Process process = Runtime.getRuntime().exec("/usr/bin/program");
03 (new Thread() {
04 public void run() {
05 try {
06 while(process.getInputStream().read()!=-1);
07 } catch (IOException ex) {
08 }
09 }}).start();
10 (new Thread() {
11 public void run() {
12 try {
13 while(process.getErrorStream().read()!=-1);
14 } catch (IOException ex) {
15 }
16 }}).start();
17 try {
18 process.waitFor();
19 } catch (InterruptedException ex) {
20 }
21 } catch (IOException ex) {
22 ex.printStackTrace();
23 }