19a1eeea9SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
39a1eeea9SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49a1eeea9SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59a1eeea9SAndrew Rist  * distributed with this work for additional information
69a1eeea9SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79a1eeea9SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89a1eeea9SAndrew Rist  * "License"); you may not use this file except in compliance
99a1eeea9SAndrew Rist  * with the License.  You may obtain a copy of the License at
109a1eeea9SAndrew Rist  *
119a1eeea9SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
129a1eeea9SAndrew Rist  *
139a1eeea9SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149a1eeea9SAndrew Rist  * software distributed under the License is distributed on an
159a1eeea9SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169a1eeea9SAndrew Rist  * KIND, either express or implied.  See the License for the
179a1eeea9SAndrew Rist  * specific language governing permissions and limitations
189a1eeea9SAndrew Rist  * under the License.
199a1eeea9SAndrew Rist  *
209a1eeea9SAndrew Rist  *************************************************************/
219a1eeea9SAndrew Rist 
229a1eeea9SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package org.openoffice.setup.Util;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import java.io.BufferedReader;
27cdf0e10cSrcweir import java.io.IOException;
28cdf0e10cSrcweir import java.io.InputStreamReader;
29cdf0e10cSrcweir import java.util.Vector;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir public class ExecuteProcess {
32cdf0e10cSrcweir 
ExecuteProcess()33cdf0e10cSrcweir     private ExecuteProcess() {
34cdf0e10cSrcweir     }
35cdf0e10cSrcweir 
executeProcessReturnValue(String[] command)36cdf0e10cSrcweir     static public int executeProcessReturnValue(String[] command) {
37*a893be29SPedro Giffuni         // usage of String arrays because of blanks in paths
38cdf0e10cSrcweir         int returnValue = 0;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir         try {
41cdf0e10cSrcweir             Process p = Runtime.getRuntime().exec(command);
42cdf0e10cSrcweir             p.waitFor();
43cdf0e10cSrcweir             returnValue = p.exitValue();
44cdf0e10cSrcweir         } catch ( IOException ioe ) {
45cdf0e10cSrcweir             System.err.println("IOError:" + ioe );
46cdf0e10cSrcweir         } catch ( InterruptedException ie ) {
47cdf0e10cSrcweir             System.err.println("Interrupted Exception:" + ie );
48cdf0e10cSrcweir         }
49cdf0e10cSrcweir 
50cdf0e10cSrcweir         return returnValue;
51cdf0e10cSrcweir     }
52cdf0e10cSrcweir 
executeProcessReturnVector(String[] command, Vector returnVector, Vector returnErrorVector)53cdf0e10cSrcweir     static public int executeProcessReturnVector(String[] command, Vector returnVector, Vector returnErrorVector) {
54*a893be29SPedro Giffuni         // usage of String arrays because of blanks in paths
55cdf0e10cSrcweir         int returnValue = -3;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir         try {
58cdf0e10cSrcweir             Process p = Runtime.getRuntime().exec(command);
59cdf0e10cSrcweir 
60cdf0e10cSrcweir             BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
61cdf0e10cSrcweir             BufferedReader errorIn = new BufferedReader(new InputStreamReader(p.getErrorStream()));
62cdf0e10cSrcweir             for ( String s; ( s = in.readLine()) != null; ) {
63cdf0e10cSrcweir                 returnVector.add(s);
64cdf0e10cSrcweir             }
65cdf0e10cSrcweir             for ( String t; ( t = errorIn.readLine()) != null; ) {
66cdf0e10cSrcweir                 returnErrorVector.add(t);
67cdf0e10cSrcweir             }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir             p.waitFor();
70cdf0e10cSrcweir             returnValue = p.exitValue();
71cdf0e10cSrcweir 
72cdf0e10cSrcweir         } catch ( InterruptedException ioe ) {
73cdf0e10cSrcweir             System.err.println("Interrupted Exception Error: " + ioe );
74cdf0e10cSrcweir         } catch ( IOException ioe ) {
75cdf0e10cSrcweir             System.err.println("IOError: " + ioe );
76cdf0e10cSrcweir         }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         return returnValue;
79cdf0e10cSrcweir     }
80cdf0e10cSrcweir 
executeProcessReturnVectorEnv(String[] command, String[] envP, Vector returnVector, Vector returnErrorVector)81cdf0e10cSrcweir     static public int executeProcessReturnVectorEnv(String[] command, String[] envP, Vector returnVector, Vector returnErrorVector) {
82*a893be29SPedro Giffuni         // usage of String arrays because of blanks in paths
83cdf0e10cSrcweir         int returnValue = -3;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         try {
86cdf0e10cSrcweir             Process p = Runtime.getRuntime().exec(command, envP);
87cdf0e10cSrcweir 
88cdf0e10cSrcweir             // Solaris has to use the ErrorStream (do not log license texts), Linux the InputStream
89cdf0e10cSrcweir             BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
90cdf0e10cSrcweir             BufferedReader errorIn = new BufferedReader(new InputStreamReader(p.getErrorStream()));
91cdf0e10cSrcweir             for ( String s; ( s = in.readLine()) != null; ) {
92cdf0e10cSrcweir                 returnVector.add(s);
93cdf0e10cSrcweir             }
94cdf0e10cSrcweir             for ( String t; ( t = errorIn.readLine()) != null; ) {
95cdf0e10cSrcweir                 returnErrorVector.add(t);
96cdf0e10cSrcweir             }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir             p.waitFor();
99cdf0e10cSrcweir             returnValue = p.exitValue();
100cdf0e10cSrcweir 
101cdf0e10cSrcweir         } catch ( InterruptedException ioe ) {
102cdf0e10cSrcweir             System.err.println("Interrupted Exception Error: " + ioe );
103cdf0e10cSrcweir         } catch ( IOException ioe ) {
104cdf0e10cSrcweir             System.err.println("IOError: " + ioe );
105cdf0e10cSrcweir         }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir         return returnValue;
108cdf0e10cSrcweir     }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir }
111