001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031 package org.openoffice.setup.Util;
032
033 import java.io.BufferedReader;
034 import java.io.IOException;
035 import java.io.InputStreamReader;
036 import java.util.Vector;
037
038 public class ExecuteProcess {
039
040 private ExecuteProcess() {
041 }
042
043 static public int executeProcessReturnValue(String[] command) {
044
045 int returnValue = 0;
046
047 try {
048 Process p = Runtime.getRuntime().exec(command);
049 p.waitFor();
050 returnValue = p.exitValue();
051 } catch ( IOException ioe ) {
052 System.err.println("IOError:" + ioe );
053 } catch ( InterruptedException ie ) {
054 System.err.println("Interrupted Exception:" + ie );
055 }
056
057 return returnValue;
058 }
059
060 static public int executeProcessReturnVector(String[] command, Vector returnVector, Vector returnErrorVector) {
061
062 int returnValue = -3;
063
064 try {
065 Process p = Runtime.getRuntime().exec(command);
066
067 BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
068 BufferedReader errorIn = new BufferedReader(new InputStreamReader(p.getErrorStream()));
069 for ( String s; ( s = in.readLine()) != null; ) {
070 returnVector.add(s);
071 }
072 for ( String t; ( t = errorIn.readLine()) != null; ) {
073 returnErrorVector.add(t);
074 }
075
076 p.waitFor();
077 returnValue = p.exitValue();
078
079 } catch ( InterruptedException ioe ) {
080 System.err.println("Interrupted Exception Error: " + ioe );
081 } catch ( IOException ioe ) {
082 System.err.println("IOError: " + ioe );
083 }
084
085 return returnValue;
086 }
087
088 static public int executeProcessReturnVectorEnv(String[] command, String[] envP, Vector returnVector, Vector returnErrorVector) {
089
090 int returnValue = -3;
091
092 try {
093 Process p = Runtime.getRuntime().exec(command, envP);
094
095
096 BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
097 BufferedReader errorIn = new BufferedReader(new InputStreamReader(p.getErrorStream()));
098 for ( String s; ( s = in.readLine()) != null; ) {
099 returnVector.add(s);
100 }
101 for ( String t; ( t = errorIn.readLine()) != null; ) {
102 returnErrorVector.add(t);
103 }
104
105 p.waitFor();
106 returnValue = p.exitValue();
107
108 } catch ( InterruptedException ioe ) {
109 System.err.println("Interrupted Exception Error: " + ioe );
110 } catch ( IOException ioe ) {
111 System.err.println("IOError: " + ioe );
112 }
113
114 return returnValue;
115 }
116
117 }