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