update dev300-m58
[ooovba.git] / scripting / workben / installer / ExecCmd.java
blob8ec47ef61d23241aa5a4e5808b73801cda028a96
1 package installer;
2 import java.util.*;
3 import java.io.*;
4 public class ExecCmd
7 public boolean exec( String cmd, String[] env )
9 System.out.println("About to exectute " + cmd);
10 final Process p;
11 boolean result = false;
12 try
14 Runtime rt = Runtime.getRuntime();
15 p=rt.exec( cmd, env );
16 new Thread(new Runnable() {
17 public void run()
19 BufferedReader br_in = null;
20 try
22 br_in = new BufferedReader(new InputStreamReader(p.getInputStream()));
23 String buff = null;
24 while ((buff = br_in.readLine()) != null)
26 System.out.println("Process out :" + buff);
27 /*try
29 Thread.sleep(100);
31 catch(Exception e) {}*/
33 System.out.println("finished reading out");
35 catch (IOException ioe)
37 System.out.println("Exception caught printing javac result");
38 ioe.printStackTrace();
40 finally
42 if ( br_in != null )
44 try
46 br_in.close();
48 catch( Exception e ) {} // nothing can be done
51 } } ).start();
53 new Thread(new Runnable() {
54 public void run() {
55 BufferedReader br_err = null;
56 try {
57 br_err = new BufferedReader(new InputStreamReader(p.getErrorStream()));
58 String buff = null;
59 while ((buff = br_err.readLine()) != null) {
60 System.out.println("Process err :" + buff);
61 /*try {Thread.sleep(100); } catch(Exception e) {}*/
63 System.out.println("finished reading err");
64 } catch (IOException ioe) {
65 System.out.println("Exception caught printing javac result");
66 ioe.printStackTrace();
68 finally
70 if ( br_err != null )
72 try
74 br_err.close();
76 catch( Exception e ) {} // nothing can be done
79 } }).start();
80 int exitcode = p.waitFor();
81 if ( exitcode != 0 )
83 System.out.println("cmd [" + cmd + "] failed" );
84 result= false;
86 else
88 System.out.println("cmd [" + cmd + "] completed successfully");
89 result= true;
92 catch (Exception e) {
93 System.out.println("Exception");
94 e.printStackTrace();
96 System.out.println("command complete");
97 return result;