rshell
1.2
|
Instantiated by Command_Set or Command_List to run user defined single commands. More...
#include <Command_Element.h>
Public Member Functions | |
Command (string c) | |
Constructor. More... | |
int | execute () |
Executes a single command by fork and execvp. More... | |
int | file_check () |
Attempts to call stat on a given path and returns the response. More... | |
int | redirect_handler () |
manages any command with pipes or redirects More... | |
char ** | to_char_array (vector< string > cmd) |
converts the c++ vector<string> into c function friendly char** More... | |
string | str () |
Returns a string representing a formatted version of the single command. More... | |
Protected Attributes | |
vector< string > | parameters |
Instantiated by Command_Set or Command_List to run user defined single commands.
Command::Command | ( | string | c | ) |
Constructor.
Contains the executable at index=0 and parameters after
s | input string to be parsed |
Constructor takes the string passed in and sends it to Parse_Single_Command. The result of the parsing is a vector of strings stored in 'parameters'
|
virtual |
Executes a single command by fork and execvp.
First check for the 'exit' command ignoring any parameters passed with it. Return EXIT if the 'exit' command is passed. This return type is handled by the Command_Set which instatiated this. The vector of strings is then converted in O(n) time to a char** to be passed to execvp. The process is then forked and the PID is analyzed to determine success of the forking and which process is which. Finally when the child process is resolved (by fail or success) its return code is passed to the parent and then back to Command_Set.
Implements Command_Element.
int Command::file_check | ( | ) |
Attempts to call stat on a given path and returns the response.
This method determines if the the second element in parameters is a path or a flag, and then calls stat and stat macros to determine the return code.
int Command::redirect_handler | ( | ) |
manages any command with pipes or redirects
This method handles and command that contains pipes or redirects. It first separates | > < >> from the commands. If a < is found it is expected to be the first of all pipes and redirects. Likewise if a > or >> is found it is expected to be the last. Pipes are only acceptable in between.
|
virtual |
Returns a string representing a formatted version of the single command.
Return a string of the 'parameters' vector seperated by a space
Implements Command_Element.
char ** Command::to_char_array | ( | vector< string > | cmd | ) |
converts the c++ vector<string> into c function friendly char**