OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
System.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: System.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.2 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: System
10 // The class for the OPAL SYSTEM command.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2002/01/17 22:18:36 $
15 // $Author: jsberg $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "BasicActions/System.h"
20 
21 #include "Ippl.h"
22 #include "Attributes/Attributes.h"
23 
24 #include <cstdlib>
25 // Class System
26 // ------------------------------------------------------------------------
27 
29  Action(1, "SYSTEM",
30  "The \"SYSTEM\" statement sends a command string to the "
31  "operating system.") {
33  ("CMD", "A system command to be executed");
34 
36 }
37 
38 
39 System::System(const std::string &name, System *parent):
40  Action(name, parent)
41 {}
42 
43 
45 {}
46 
47 
48 System *System::clone(const std::string &name) {
49  return new System(name, this);
50 }
51 
52 
54  if (Ippl::myNode() == 0) {
55  std::string command = Attributes::getString(itsAttr[0]);
56 
57  int res = system(command.c_str());
58  if (res!=0)
59  ERRORMSG("SYSTEM call failed" << endl);
60  }
61 }
62 
63 void System::parse(Statement &statement) {
64  parseShortcut(statement);
65 }
virtual System * clone(const std::string &name)
Make clone.
Definition: System.cpp:48
virtual void parseShortcut(Statement &)
Parser for single-attribute commands.
Definition: Object.cpp:132
The base class for all OPAL actions.
Definition: Action.h:30
#define ERRORMSG(msg)
Definition: IpplInfo.h:399
The SYSTEM command.
Definition: System.h:28
static int myNode()
Definition: IpplInfo.cpp:794
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
virtual void execute()
Execute the command.
Definition: System.cpp:53
Interface for statements.
Definition: Statement.h:38
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:194
System()
Exemplar constructor.
Definition: System.cpp:28
virtual ~System()
Definition: System.cpp:44
virtual void parse(Statement &)
Parse command (special for one-attribute command).
Definition: System.cpp:63
const std::string name
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:296
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307