Simple command structure.
More...
#include <msh_command.h>
|
|
using | args_t = std::vector<std::string> |
| |
|
using | argv_c_t = std::vector<char *> |
| |
|
using | redirects_t = std::vector<redirect> |
| |
|
|
| simple_command (tokens_t tokens) |
| |
| bool | construct () |
| | Construct the command.
|
| |
| int | do_redirects (std::vector< int > *fd_to_close) |
| | Perform redirections attached to the command.
|
| |
| void | undo_redirects (std::vector< int > const &fd_to_close) |
| | Undo redirections attached to the command.
|
| |
| int | execute (int in=STDIN_FILENO, int out=STDOUT_FILENO, int flags=0) |
| | Execute the command.
|
| |
|
|
tokens_t | tokens |
| |
|
args_t | argv |
| |
|
argv_c_t | argv_c |
| |
|
std::array< int, 3 > | saved_fds {} |
| |
|
redirects_t | redirects |
| |
|
int | argc = 0 |
| |
Simple command structure.
The minimal unit of execution. Requires a std::vector of tokens_t to be constructed.
On execute() the tokens are processed and the command is executed using msh_exec_simple().
- See also
- msh_exec_simple()
◆ construct()
| bool simple_command::construct |
( |
| ) |
|
|
inline |
Construct the command.
Constructs the command arguments array argv_c and the number of arguments argc.
- Note
- Should only be called after tokens processing.
◆ do_redirects()
| int simple_command::do_redirects |
( |
std::vector< int > * | fd_to_close | ) |
|
|
inline |
Perform redirections attached to the command.
- Parameters
-
| fd_to_close | Vector of file descriptors to close after the command is executed. |
- Returns
- 0 on success, error code otherwise.
- Note
- All standard file descriptors are saved before performing the redirections.
-
File descriptors opened by redirections are added to
fd_to_close. They should be closed after the command is executed or earlier if the command fails.
- See also
- msh_redirects.h
◆ execute()
| int simple_command::execute |
( |
int | in = STDIN_FILENO, |
|
|
int | out = STDOUT_FILENO, |
|
|
int | flags = 0 ) |
|
inline |
Execute the command.
- Parameters
-
| in | File descriptor to use as stdin. |
| out | File descriptor to use as stdout |
| flags | Flags to pass to msh_exec_simple(). |
- Returns
- Exit code of the command.
- See also
- msh_exec_simple()
◆ undo_redirects()
| void simple_command::undo_redirects |
( |
std::vector< int > const & | fd_to_close | ) |
|
|
inline |
Undo redirections attached to the command.
- Parameters
-
| fd_to_close | Vector of file descriptors to close. |
- Note
- Should be called after the command is executed or earlier if the command fails.
Restores standard file descriptors and closes all file descriptors specified by fd_to_close.
The documentation for this struct was generated from the following file: