/Users/lyon/j4p/src/javagroup/misc/LaunchProcess.java

1    /* 
2     * Copyright (C) 1997, 1988 Luke Gorrie 
3     * 
4     * This library is free software; you can redistribute it and/or 
5     * modify it under the terms of the GNU Library General Public 
6     * License as published by the Free Software Foundation; either 
7     * version 2 of the License, or (at your option) any later version. 
8     * 
9     * This library is distributed in the hope that it will be useful, 
10    * but WITHOUT ANY WARRANTY; without even the implied warranty of 
11    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12    * Library General Public License for more details. 
13    * 
14    * You should have received a copy of the GNU Library General Public 
15    * License along with this library; if not, write to the 
16    * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
17    * MA 02139, USA. 
18    */ 
19    
20   package javagroup.misc; 
21    
22   import javagroup.process.JProcess; 
23   import javagroup.process.ProcessCreationException; 
24   import javagroup.process.ProcessManager; 
25   import javagroup.process.ProcessManagerHolder; 
26    
27   /** 
28    * Simple class defining a "main" method for starting processes. 
29    * 
30    * @author Luke Gorrie 
31    * @version $Revision: 1.1 $, $Date: 1999/01/05 11:43:11 $ 
32    */ 
33   public class LaunchProcess { 
34       public static void main(String[] args) { 
35           if (args.length == 0) { 
36               System.err.println( 
37                       "Usage: LaunchProcess [-eclasspath url[,url]*] classname arg*"); 
38               System.exit(1); 
39           } 
40           StringBuffer spec_buffer = new StringBuffer(); 
41           for (int i = 0; i < args.length; i++) { 
42               spec_buffer.append(args[i]); 
43               spec_buffer.append(" "); 
44           } 
45           String spec = spec_buffer.toString(); 
46           ProcessManager pm = ProcessManagerHolder.getProcessManager(); 
47           try { 
48               JProcess process = pm.createProcessFromString(spec); 
49               process.launch(); 
50               process.waitFor(); 
51               System.err.println( 
52                       "Process \"" + process.toString() + "\" finished."); 
53           } catch (ProcessCreationException e) { 
54               System.err.println("Unable to create process: " + e); 
55               System.exit(1); 
56           } 
57       } 
58   } 
59    
60