1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package org.openoffice.setup.Util; 29 30 import java.io.BufferedReader; 31 import java.io.IOException; 32 import java.io.InputStreamReader; 33 import java.util.Vector; 34 35 public class ExecuteProcess { 36 37 private ExecuteProcess() { 38 } 39 40 static public int executeProcessReturnValue(String[] command) { 41 // usage of String arrays because of blanks in pathes 42 int returnValue = 0; 43 44 try { 45 Process p = Runtime.getRuntime().exec(command); 46 p.waitFor(); 47 returnValue = p.exitValue(); 48 } catch ( IOException ioe ) { 49 System.err.println("IOError:" + ioe ); 50 } catch ( InterruptedException ie ) { 51 System.err.println("Interrupted Exception:" + ie ); 52 } 53 54 return returnValue; 55 } 56 57 static public int executeProcessReturnVector(String[] command, Vector returnVector, Vector returnErrorVector) { 58 // usage of String arrays because of blanks in pathes 59 int returnValue = -3; 60 61 try { 62 Process p = Runtime.getRuntime().exec(command); 63 64 BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); 65 BufferedReader errorIn = new BufferedReader(new InputStreamReader(p.getErrorStream())); 66 for ( String s; ( s = in.readLine()) != null; ) { 67 returnVector.add(s); 68 } 69 for ( String t; ( t = errorIn.readLine()) != null; ) { 70 returnErrorVector.add(t); 71 } 72 73 p.waitFor(); 74 returnValue = p.exitValue(); 75 76 } catch ( InterruptedException ioe ) { 77 System.err.println("Interrupted Exception Error: " + ioe ); 78 } catch ( IOException ioe ) { 79 System.err.println("IOError: " + ioe ); 80 } 81 82 return returnValue; 83 } 84 85 static public int executeProcessReturnVectorEnv(String[] command, String[] envP, Vector returnVector, Vector returnErrorVector) { 86 // usage of String arrays because of blanks in pathes 87 int returnValue = -3; 88 89 try { 90 Process p = Runtime.getRuntime().exec(command, envP); 91 92 // Solaris has to use the ErrorStream (do not log license texts), Linux the InputStream 93 BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); 94 BufferedReader errorIn = new BufferedReader(new InputStreamReader(p.getErrorStream())); 95 for ( String s; ( s = in.readLine()) != null; ) { 96 returnVector.add(s); 97 } 98 for ( String t; ( t = errorIn.readLine()) != null; ) { 99 returnErrorVector.add(t); 100 } 101 102 p.waitFor(); 103 returnValue = p.exitValue(); 104 105 } catch ( InterruptedException ioe ) { 106 System.err.println("Interrupted Exception Error: " + ioe ); 107 } catch ( IOException ioe ) { 108 System.err.println("IOError: " + ioe ); 109 } 110 111 return returnValue; 112 } 113 114 } 115