View Javadoc

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