TShellCommand provides a lightweight interface for executing external shell commands and capturing their output. It reads from the command’s standard output stream and accumulates the text in a buffer. The captured output is split into individual lines and stored in the class’s underlying StringVector.
Method Run can be sequentially invoked multiple times to aggregate the output of several shell commands. With the static Run variant, the same buffer and vector is to be passed to continue appending. With the non-static Run, parameter keepCurrent controls whether existing content is retained or not.
Definition at line 40 of file shellcommand.inl.
Public Type Index: | |
| using | AllocatorType = TAllocator |
| The allocator type that TAllocator specifies. | |
| using | StringVector = strings::util::TStringVector<nchar, TAllocator> |
| The base type of this class. | |
Public Type Index: inherited from alib::strings::util::TStringVector< nchar, lang::HeapAllocator > | |
| using | AllocatorType |
| The allocator type that TAllocator specifies. | |
Public Static Method Index: | |
| static int | Run (const NCString &cmd, strings::TAString< nchar, AllocatorType > &readBuffer, StringVector *lines=nullptr) |
Public Field Index: | |
| strings::TAString< nchar, AllocatorType > | ReadBuffer |
| The input buffer, collecting the output of the invoked shell command(s). | |
Public Method Index: | |
| TShellCommand () | |
| Default constructor. Usable with type HeapAllocator. | |
| TShellCommand (AllocatorType &ma) | |
| int | Run (const NCString &cmd, lang::CurrentData keepData=lang::CurrentData::Clear) |
Public Method Index: inherited from alib::strings::util::TStringVector< nchar, lang::HeapAllocator > | |
| TStringVector () | |
| Constructor. | |
| TStringVector () | |
| Constructor. | |
| TStringVector (AllocatorType &pAllocator) | |
| TStringVector (AllocatorType &pAllocator) | |
| ~TStringVector ()=default | |
| Destructor. | |
| ~TStringVector ()=default | |
| Destructor. | |
| integer | Add (const strings::TString< nchar > &src) |
| integer | Add (const strings::TString< nchar > &src) |
| AllocatorType & | GetAllocator () noexcept |
| AllocatorType & | GetAllocator () noexcept |
| integer | Size () const noexcept |
| integer | Size () const noexcept |
| String | TryGet (integer idx) |
| String | TryGet (integer idx) |
Additional Inherited Members | |
Protected Type Index: inherited from alib::strings::util::TStringVector< nchar, lang::HeapAllocator > | |
| using | vectorBase |
| The vector type that TAllocator specifies. | |
| using alib::system::TShellCommand< TAllocator >::AllocatorType = TAllocator |
The allocator type that TAllocator specifies.
Definition at line 44 of file shellcommand.inl.
| using alib::system::TShellCommand< TAllocator >::StringVector = strings::util::TStringVector<nchar, TAllocator> |
The base type of this class.
Definition at line 47 of file shellcommand.inl.
| strings::TAString<nchar, AllocatorType> alib::system::TShellCommand< TAllocator >::ReadBuffer |
The input buffer, collecting the output of the invoked shell command(s).
Definition at line 50 of file shellcommand.inl.
|
inline |
Default constructor. Usable with type HeapAllocator.
Definition at line 53 of file shellcommand.inl.
|
inline |
Constructor taking an allocator.
| ma | The allocator to use. |
Definition at line 57 of file shellcommand.inl.
|
inline |
Executes the given command line by invoking the static variant of this method passing member ReadBuffer and the inherited string vector (*this).
| cmd | The command to execute. |
| keepData | Denotes whether any prior results are kept or not. |
Definition at line 67 of file shellcommand.inl.
|
inlinestatic |
Executes the given command line.
The given readBuffer and vector lines are not reset. Instead the command result is appended to both. If this is not wanted, methods Reset and clear have to be invoked prior to calling this method.
| cmd | The command to execute. |
| readBuffer | A string buffer to receive the command's output. |
| lines | An optional pointer to a vector of strings, which receives the lines of the output text. |
Definition at line 83 of file shellcommand.inl.