OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
System.cpp
Go to the documentation of this file.
1//
2// Class System
3// The class for OPAL SYSTEM command on a single core.
4//
5// Copyright (c) 2000 - 2021, Paul Scherrer Institut, Villigen PSI, Switzerland
6// All rights reserved
7//
8// This file is part of OPAL.
9//
10// OPAL is free software: you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// You should have received a copy of the GNU General Public License
16// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17//
18#include "BasicActions/System.h"
19
21#include "Utility/IpplInfo.h"
22
23#include <cstdlib>
24
26 Action(1, "SYSTEM",
27 "The \"SYSTEM\" statement sends a command string to the "
28 "operating system.") {
30 ("CMD", "A system command to be executed");
31
33}
34
35
36System::System(const std::string& name, System* parent):
37 Action(name, parent)
38{}
39
40
42{}
43
44
45System* System::clone(const std::string& name) {
46 return new System(name, this);
47}
48
49
51 if (Ippl::myNode() == 0) {
52 std::string command = Attributes::getString(itsAttr[0]);
53
54 int res = system(command.c_str());
55 if (res!=0)
56 ERRORMSG("SYSTEM call failed" << endl);
57 }
58}
59
60void System::parse(Statement& statement) {
61 parseShortcut(statement);
62}
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
#define ERRORMSG(msg)
Definition: IpplInfo.h:350
const std::string name
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:343
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:332
The base class for all OPAL actions.
Definition: Action.h:30
virtual void parseShortcut(Statement &, bool eval=true)
Parser for single-attribute commands.
Definition: Object.cpp:129
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:191
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
Definition: System.h:24
virtual ~System()
Definition: System.cpp:41
virtual System * clone(const std::string &name)
Make clone.
Definition: System.cpp:45
virtual void execute()
Execute the command.
Definition: System.cpp:50
virtual void parse(Statement &)
Parse command (special for one-attribute command).
Definition: System.cpp:60
System()
Exemplar constructor.
Definition: System.cpp:25
Interface for statements.
Definition: Statement.h:38
static int myNode()
Definition: IpplInfo.cpp:691