cisst-saw
Loading...
Searching...
No Matches
osaPipeExec Class Reference

#include <osaPipeExec.h>

Public Member Functions

 osaPipeExec (const std::string &name="unnamed")
 ~osaPipeExec (void)
bool Open (const std::string &executable, const std::string &mode, bool noWindow=false)
bool Open (const std::string &executable, const std::vector< std::string > &parameters, const std::string &mode, bool noWindow=false)
bool Close (bool killProcess=true)
int Read (char *buffer, int maxLength) const
std::string Read (int maxLength) const
int ReadUntil (char *buffer, int maxLength, char stopChar, double timeoutSec=0.0) const
std::string ReadUntil (int maxLength, char stopChar, double timeoutSec=0.0) const
std::string ReadString (int maxLength, double timeoutSec=0.0) const
int Write (const char *buffer)
int Write (const char *buffer, int n)
int Write (const std::string &s)
int Write (const std::string &s, int n)
bool IsConnected (void) const
bool IsProcessRunning (void) const
const std::string & GetName (void) const

Friends

class osaPipeExecTest

Constructor & Destructor Documentation

◆ osaPipeExec()

osaPipeExec::osaPipeExec ( const std::string & name = "unnamed")

Constructor with name

◆ ~osaPipeExec()

osaPipeExec::~osaPipeExec ( void )

Destructor calls Close()

Member Function Documentation

◆ Close()

bool osaPipeExec::Close ( bool killProcess = true)

Close the pipe and optionally kill the child process. Returns: true if killProcess is false and pipe successfully closed OR if killProcess is true and process successfully terminated (even if pipe not successfully closed); false otherwise

◆ GetName()

const std::string & osaPipeExec::GetName ( void ) const

Get name provided in constructor.

◆ IsConnected()

bool osaPipeExec::IsConnected ( void ) const

Indicate if the pipe is opened (or at least supposed to be opened)

◆ IsProcessRunning()

bool osaPipeExec::IsProcessRunning ( void ) const

Returns true if the child process is still running.

◆ Open() [1/2]

bool osaPipeExec::Open ( const std::string & executable,
const std::string & mode,
bool noWindow = false )

Open a pipe using an existing executable and specifying read/write mode. Mode can be "r", "w", or "rw" specifying which direction(s) the pipe should go. Returns true if the Open succeeded, false otherwise. On Microsoft Windows, the optional parameter noWindow prevents a new console window from being displayed.

◆ Open() [2/2]

bool osaPipeExec::Open ( const std::string & executable,
const std::vector< std::string > & parameters,
const std::string & mode,
bool noWindow = false )

Open a pipe using an existing executable with a vector of arguments and specifying read/write mode. Mode can be "r", "w", or "rw" specifying which direction(s) the pipe should go. Returns true if the Open succeeded, false otherwise. On Microsoft Windows, the optional parameter noWindow prevents a new console window from being displayed.

◆ Read() [1/2]

int osaPipeExec::Read ( char * buffer,
int maxLength ) const

Read at most maxLength characters from the pipe into buffer. Return number of characters read or -1 for an error

◆ Read() [2/2]

std::string osaPipeExec::Read ( int maxLength) const

Read at most maxLength characters from the pipe, including '\0', and return an std::string containing those characters or empty string for an error

◆ ReadString()

std::string osaPipeExec::ReadString ( int maxLength,
double timeoutSec = 0.0 ) const

Equivalent to ReadUntil(maxLength, '\0', timeoutSec)

◆ ReadUntil() [1/2]

int osaPipeExec::ReadUntil ( char * buffer,
int maxLength,
char stopChar,
double timeoutSec = 0.0 ) const

Read at most maxLength characters from the pipe, but stop reading if stopChar is read or if timeout expires (timeoutSec <= 0 means no timeout). Return the number of characters read.

◆ ReadUntil() [2/2]

std::string osaPipeExec::ReadUntil ( int maxLength,
char stopChar,
double timeoutSec = 0.0 ) const

std::string version of ReadUntil. Return the number of characters read

◆ Write() [1/4]

int osaPipeExec::Write ( const char * buffer)

Write the null-terminated buffer to the pipe. Return the number of characters written or -1 for an error

◆ Write() [2/4]

int osaPipeExec::Write ( const char * buffer,
int n )

Write the first n characters of buffer to pipe. Return the number of characters written or -1 for an error

◆ Write() [3/4]

int osaPipeExec::Write ( const std::string & s)

Write s to the pipe and return the number of characters read or -1 for an error

◆ Write() [4/4]

int osaPipeExec::Write ( const std::string & s,
int n )

Write the first n characters of s to pipe. Return the number of characters written or -1 for an error

◆ osaPipeExecTest

friend class osaPipeExecTest
friend

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