KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > process > SimpleExternalProcess


1 /*
2 * ################################################################
3 *
4 * ProActive: The Java(TM) library for Parallel, Distributed,
5 * Concurrent computing with Security and Mobility
6 *
7 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8 * Contact: proactive-support@inria.fr
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library 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 GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * Initial developer(s): The ProActive Team
26 * http://www.inria.fr/oasis/ProActive/contacts.html
27 * Contributor(s):
28 *
29 * ################################################################
30 */

31 package org.objectweb.proactive.core.process;
32
33 import org.objectweb.proactive.core.util.MessageLogger;
34
35 /**
36  * <p>
37  * The SimpleExternalProcess class is able to start any command line
38  * </p>
39  * <p>
40  * For instance
41  * </p><pre>
42  * ..............
43  * SimpleExternalProcess p = new SimpleExternalProcess("ls -la");
44  * ..............
45  * </pre>
46  * <p>
47  * The previous piece of code will run locally the command "ls -la"
48  *
49  * @author ProActive Team
50  * @version 1.0, 2002/06/20
51  * @since ProActive 0.9.3
52  */

53
54 public class SimpleExternalProcess extends AbstractExternalProcess {
55   
56   private String JavaDoc targetCommand;
57   
58   //
59
// -- CONSTRUCTORS -----------------------------------------------
60
//
61

62   /**
63    * Creates a new SimpleExternalProcess
64    * @param targetCommand The command to run
65    */

66   public SimpleExternalProcess(String JavaDoc targetCommand) {
67     this(new StandardOutputMessageLogger(), targetCommand);
68   }
69   
70   
71   /**
72    * Creates a new SimpleExternalProcess
73    * @param messageLogger The logger that handles input and error stream of this process
74    * @param targetCommand The command to run
75    */

76   public SimpleExternalProcess(MessageLogger messageLogger, String JavaDoc targetCommand) {
77     this(messageLogger, messageLogger, targetCommand);
78   }
79   
80   
81   /**
82    * Creates a new SimpleExternalProcess
83    * @param inputMessageLogger The logger that handles input stream of this process
84    * @param errorMessageLogger The logger that handles error stream of this process
85    * @param targetCommand The command to run
86    */

87   public SimpleExternalProcess(MessageLogger inputMessageLogger, MessageLogger errorMessageLogger, String JavaDoc targetCommand) {
88     super(inputMessageLogger, errorMessageLogger);
89     this.targetCommand = targetCommand;
90   }
91   
92
93   //
94
// -- PUBLIC METHODS -----------------------------------------------
95
//
96

97   public static void main(String JavaDoc[] args) {
98     try {
99       String JavaDoc targetCommand = null;
100       if (args.length > 0)
101         targetCommand = args[0];
102       else targetCommand = "ls -las";
103       SimpleExternalProcess p = new SimpleExternalProcess(targetCommand);
104       p.startProcess();
105     } catch (Exception JavaDoc e) {
106       e.printStackTrace();
107     }
108   }
109
110
111   //
112
// -- PROTECTED METHODS -----------------------------------------------
113
//
114

115   protected String JavaDoc buildCommand() {
116     return targetCommand;
117   }
118   
119   
120   //
121
// -- PRIVATE METHODS -----------------------------------------------
122
//
123

124
125 }
126
Popular Tags