Rose
Classes | Public Member Functions | Protected Attributes | List of all members
rose::Command Class Reference

Execute a program and gather the output. More...

#include <Command.h>

Collaboration diagram for rose::Command:
Collaboration graph
[legend]

Classes

struct  PipeClose
 Close the pipe and keep the exit status. More...
 

Public Member Functions

 Command (const char *command)
 Constructor. More...
 
int wait ()
 Gather the command output and wait for it to exit. More...
 
int statusCode ()
 Get the command exit status code. More...
 
const std::string & result () const
 Get the output of the command. More...
 

Protected Attributes

std::string mResult {}
 The output of the command.
 
PipeClose mPipeClose {}
 The pipe closer.
 
std::unique_ptr< FILE, PipeClosemPipe
 The pipe from the command.
 

Detailed Description

Execute a program and gather the output.

Constructor & Destructor Documentation

◆ Command()

rose::Command::Command ( const char *  command)
inlineexplicit

Constructor.

Parameters
commandThe command to execute. See popen()

The pipe is opened with a call to popen(command,"r"). A call to wait will pause execution and gather the output and the exit status when the command exits.

Member Function Documentation

◆ result()

const std::string& rose::Command::result ( ) const
inline

Get the output of the command.

Returns
A std::string with the command output.

◆ statusCode()

int rose::Command::statusCode ( )
inline

Get the command exit status code.

Returns
The exit status gathered by pclose().

◆ wait()

int rose::Command::wait ( )
inline

Gather the command output and wait for it to exit.

Returns
The exit status gathered by pclose().

The documentation for this class was generated from the following file: