Better, Faster, Freer

The LXR Cross Referencer

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Architecture: i386 ]
Version: HEAD ]

001 /*************************************************************************
002  *
003  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004  * 
005  * Copyright 2008 by Sun Microsystems, Inc.
006  *
007  * OpenOffice.org - a multi-platform office productivity suite
008  *
009  * $RCSfile: ExecuteProcess.java,v $
010  * $Revision: 1.3 $
011  *
012  * This file is part of OpenOffice.org.
013  *
014  * OpenOffice.org is free software: you can redistribute it and/or modify
015  * it under the terms of the GNU Lesser General Public License version 3
016  * only, as published by the Free Software Foundation.
017  *
018  * OpenOffice.org is distributed in the hope that it will be useful,
019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
021  * GNU Lesser General Public License version 3 for more details
022  * (a copy is included in the LICENSE file that accompanied this code).
023  *
024  * You should have received a copy of the GNU Lesser General Public License
025  * version 3 along with OpenOffice.org.  If not, see
026  * <http://www.openoffice.org/license.html>
027  * for a copy of the LGPLv3 License.
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         // usage of String arrays because of blanks in pathes
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         // usage of String arrays because of blanks in pathes
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         // usage of String arrays because of blanks in pathes
090         int returnValue = -3;
091         
092         try {
093             Process p = Runtime.getRuntime().exec(command, envP);
094 
095             // Solaris has to use the ErrorStream (do not log license texts), Linux the InputStream
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 }

source navigation ] diff markup ] identifier search ] general search ]

This page was automatically generated by the LXR engine.
The LXR team
Valid HTML 4.01!