CASM  1.1.0
A Clusters Approach to Statistical Mechanics
CASM::Popen Class Reference

#include <Popen.hh>

Detailed Description

Remember how to use popen.

Definition at line 13 of file Popen.hh.

Public Member Functions

 Popen (std::function< void(FILE *)> _popen_handler=Popen::default_popen_handler, std::function< void(int)> _pclose_handler=Popen::default_pclose_handler, bool _combine_stdout_stderr=true)
 Construct a Popen object. More...
 
void popen (std::string _command)
 Execute popen for a given command. More...
 
std::string gets () const
 Returns the stdout resulting from the last popen call. More...
 
void print (std::ostream &sout) const
 Print the last command executed and the resulting stdout. More...
 
int exit_code () const
 Returns pclose(fp)/256. More...
 

Static Public Member Functions

static void default_popen_handler (FILE *fp)
 Default popen error handler throws std::runtime_error if popen failed. More...
 
static void default_pclose_handler (int status)
 Default pclose error handler throws std::runtime_error if pclose failed. More...
 

Private Attributes

std::string m_command
 
std::string m_stdout
 
int m_pclose_result
 
std::function< void(FILE *)> m_popen_handler
 
std::function< void(int)> m_pclose_handler
 
bool m_combine_stdout_stderr
 

Constructor & Destructor Documentation

◆ Popen()

CASM::Popen::Popen ( std::function< void(FILE *)>  _popen_handler = Popen::default_popen_handler,
std::function< void(int)>  _pclose_handler = Popen::default_pclose_handler,
bool  _combine_stdout_stderr = true 
)

Construct a Popen object.

Definition at line 8 of file Popen.cc.

Member Function Documentation

◆ default_pclose_handler()

void CASM::Popen::default_pclose_handler ( int  status)
static

Default pclose error handler throws std::runtime_error if pclose failed.

Definition at line 63 of file Popen.cc.

◆ default_popen_handler()

void CASM::Popen::default_popen_handler ( FILE *  fp)
static

Default popen error handler throws std::runtime_error if popen failed.

Definition at line 55 of file Popen.cc.

◆ exit_code()

int CASM::Popen::exit_code ( ) const

Returns pclose(fp)/256.

Definition at line 52 of file Popen.cc.

◆ gets()

std::string CASM::Popen::gets ( ) const

Returns the stdout resulting from the last popen call.

Definition at line 43 of file Popen.cc.

◆ popen()

void CASM::Popen::popen ( std::string  _command)

Execute popen for a given command.

  • Uses provide error handlers
  • Stores popen stdout, which can be accessed using gets

Definition at line 19 of file Popen.cc.

◆ print()

void CASM::Popen::print ( std::ostream &  sout) const

Print the last command executed and the resulting stdout.

Definition at line 46 of file Popen.cc.

Member Data Documentation

◆ m_combine_stdout_stderr

bool CASM::Popen::m_combine_stdout_stderr
private

Definition at line 47 of file Popen.hh.

◆ m_command

std::string CASM::Popen::m_command
private

Definition at line 42 of file Popen.hh.

◆ m_pclose_handler

std::function<void(int)> CASM::Popen::m_pclose_handler
private

Definition at line 46 of file Popen.hh.

◆ m_pclose_result

int CASM::Popen::m_pclose_result
private

Definition at line 44 of file Popen.hh.

◆ m_popen_handler

std::function<void(FILE *)> CASM::Popen::m_popen_handler
private

Definition at line 45 of file Popen.hh.

◆ m_stdout

std::string CASM::Popen::m_stdout
private

Definition at line 43 of file Popen.hh.


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