-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommand.h
More file actions
70 lines (52 loc) · 1.86 KB
/
Command.h
File metadata and controls
70 lines (52 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef _Command_h_
#define _Command_h_
/** @file Command.h
* Definition of class Command.
*/
#include <string> // std::string
#include <vector> // std::vector
/** @class Command
* The program to be executed.
*/
class Command
{
private:
// The words that make up the command.
std::vector<std::string> words;
// IO redirection information
std::string input; // name of input file
std::string output; // name of output file
bool append; // use output append mode
public:
/// Initialize
Command();
/// Add a word to the command
void addWord(std::string& word);
/// Set the name of the standard input file
/// @pre There may only be one input file specification
void setInput(std::string& input);
/// Set the name of the standard output file
/// @pre There may only be one output file specification
void setOutput(std::string& output);
/// Set the name of the standard output file in append mode
/// @pre There may only be one output file specification
void setAppend(std::string& output);
/// Does this command have some input redirection?
bool hasInput() const { return !input.empty(); }
/// Does this command have some output redirection?
bool hasOutput() const { return !output.empty(); }
/// Is this an do-nothing-at-all command?
bool isEmpty() const;
/// Execute the command.
/// All words are passed to the new process as the program's argument list.
///
/// The first word is taken to be the name of the program to be executed.
/// If the name begins with '/' it is an absolute name.
/// If the name begins with "./" it is relative to the current directory.
/// Otherwise it is to be searched for using the PATH environment variable.
/// (Also see getenv(3), getcwd(3), access(2), execv(3)).
void execute();
// TODO: Add any other methods you need
};
// vim:ai:aw:ts=4:sw=4:
#endif /*_Command_h_*/