View Javadoc

1   package net.sf.tomp.xtcl.command;
2   
3   import net.sf.tomp.xtcl.Context;
4   
5   /***
6    * Executes an XTCL-external, i.e. OS/based command. 
7    * 
8    * @author tomp
9    */
10  public class ExeCommand extends AbstractCommand {
11  	
12      /*** array holding cmd name and params */
13      protected String[] cmdarray;
14  
15      /***
16       * set the array holding cmd name and params
17       * 
18       * @param r array holding cmd name and params
19       */
20      public void setCmdArray(String[] r) {
21          cmdarray = r;
22      }
23  
24      /***
25       * execute the external command with params
26       * 
27       * @param c Context
28       * @return DOCUMENT ME!
29       * @throws Exception DOCUMENT ME!
30       */
31      public int execute(Context c) throws Exception {
32          int retCode;
33  
34          try {
35              Runtime rt = Runtime.getRuntime();
36              Process p = rt.exec(cmdarray);
37  
38              retCode = p.exitValue();
39          } catch (Exception e) {
40              retCode = 1;
41          }
42  
43          return done(c, retCode);
44      }
45  
46      /***
47       * @return "RUN " + listArray(cmdarray);
48       */
49      public String toString() {
50          return "RUN " + listArray(cmdarray);
51      }
52  }
53  
54  /*
55   * The contents of this file are subject to the Mozilla Public License Version
56   * 1.1 (the "License"); you may not use this file except in compliance with the
57   * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
58   * Software distributed under the License is distributed on an "AS IS" basis,
59   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
60   * the specific language governing rights and limitations under the License. The
61   * Original Code is: all this file. The Initial Developer of the Original Code
62   * is: Tomas Pitner, Masaryk University in Brno, Czech Republic. Contributor(s):
63   */