procfetch  0.3.0
A command-line system information utility written in C++
Public Types | Public Member Functions | Static Public Member Functions | List of all members
Command Class Reference

#include <fetch.h>

Public Types

typedef std::function< void(Command)> func_type
 

Public Member Functions

string getOutput ()
 
string getErrorOutput ()
 
int getOutputLines ()
 
int getExitCode ()
 

Static Public Member Functions

static void wait ()
 
static vector< runtime_error > & getExceptions ()
 
static void exec_async (const string &cmd, const func_type &func)
 
static void exec_async (const Path &cmd, const string &arg, const func_type &func)
 
static Command exec (const string &cmd)
 

Detailed Description

Command executes a command in a subshell(shell runs on a forked process).

Sample code:

auto c = Command::exec("ls -l");
if (c.getExitcode() == 0) {
std::cout << c.getOutput();
}
static Command exec(const string &cmd)
Definition: fetch.h:273

Member Function Documentation

◆ exec()

static Command Command::exec ( const string &  cmd)
inlinestatic

Executes the specified command.

Parameters
cmdcontaining the command to call and its arguments
Returns
Command object for getting the results.
Exceptions
runtime_errorfailed to popen(3)

◆ exec_async() [1/2]

static void Command::exec_async ( const Path cmd,
const string &  arg,
const func_type &  func 
)
inlinestatic

Executes the specified command in a new thread.

Parameters
cmdcontaining the command
argarguments
functo be performed after cmd is finished

◆ exec_async() [2/2]

static void Command::exec_async ( const string &  cmd,
const func_type &  func 
)
inlinestatic

Executes the specified command in a new thread.

Parameters
cmdcontaining the command to call and its arguments
functo be performed after cmd is finished

◆ getErrorOutput()

string Command::getErrorOutput ( )
inline
Returns
get contents written by the command to standard error output

◆ getExceptions()

static vector<runtime_error>& Command::getExceptions ( )
inlinestatic
Returns
exceptions

◆ getExitCode()

int Command::getExitCode ( )
inline
Returns
get the exit code of the command.

◆ getOutput()

string Command::getOutput ( )
inline
Returns
get contents written by the command to standard output

◆ getOutputLines()

int Command::getOutputLines ( )
inline
Returns
get the new line counts of the output.

◆ wait()

static void Command::wait ( )
inlinestatic

Wait for all threads to be finished.


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