NCBI C++ ToolKit
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Private Member Functions | List of all members
CPipe Class Reference

Search Toolkit Book for CPipe

CPipe –. More...

#include <connect/ncbi_pipe.hpp>

+ Inheritance diagram for CPipe:
+ Collaboration diagram for CPipe:

Classes

class  IProcessWatcher
 Callback interface for ExecWait() More...
 

Public Types

enum  ECreateFlag {
  fStdIn_Open = 0 , fStdIn_Close = 0x001 , fStdOut_Open = 0 , fStdOut_Close = 0x002 ,
  fStdErr_Open = 0x004 , fStdErr_Close = 0 , fStdErr_Share = 0x008 , fStdErr_StdOut = 0x080 ,
  fKeepOnClose = 0x010 , fCloseOnClose = 0 , fKillOnClose = 0x020 , fSigPipe_Restore = 0x040 ,
  fNewGroup = 0x100
}
 Flags for creating standard I/O handles of the child process. More...
 
enum  EChildIOHandle {
  fStdIn = (1 << 0) , fStdOut = (1 << 1) , fStdErr = (1 << 2) , fDefault = (1 << 3) ,
  eStdIn = fStdIn , eStdOut = fStdOut , eStdErr = fStdErr , eDefault = fDefault
}
 Which of the child I/O handles to use. More...
 
enum  EFinish { eDone , eCanceled }
 ExecWait return code. More...
 
typedef unsigned int TCreateFlags
 bitwise OR of "ECreateFlag" More...
 
typedef unsigned int TChildPollMask
 bitwise OR of "EChildIOHandle" More...
 

Public Member Functions

 CPipe (size_t pipe_size=0)
 Constructor. More...
 
 CPipe (const string &cmd, const vector< string > &args, TCreateFlags create_flags=0, const string &current_dir=kEmptyStr, const char *const envp[]=0, size_t pipe_size=0)
 Constructor. More...
 
 ~CPipe (void)
 Destructor. More...
 
EIO_Status Open (const string &cmd, const vector< string > &args, TCreateFlags create_flags=0, const string &current_dir=kEmptyStr, const char *const envp[]=0, size_t pipe_size=0)
 Open pipe. More...
 
void OpenSelf (void)
 Open the standard streams of the current process. More...
 
EIO_Status Close (int *exitcode=0)
 Close pipe. More...
 
EIO_Status CloseHandle (EChildIOHandle handle)
 Close the specified child's pipe handle (even for CPipe opened with OpenSelf()). More...
 
EIO_Status SetReadHandle (EChildIOHandle from_handle)
 Set standard output handle to read data from. More...
 
EChildIOHandle GetReadHandle (void) const
 Get standard output handle to read data from. More...
 
EIO_Status Read (void *buf, size_t count, size_t *read=0, EChildIOHandle from_handle=eDefault)
 Read data from the pipe's default read handle. More...
 
EIO_Status Write (const void *data, size_t count, size_t *written=0)
 Write data to pipe (data always goes to the child's eStdIn handle). More...
 
TChildPollMask Poll (TChildPollMask mask, const STimeout *timeout=0)
 Wait for I/O event(s). More...
 
EIO_Status Status (EIO_Event direction) const
 Return a status of the last I/O operation. More...
 
EIO_Status SetTimeout (EIO_Event event, const STimeout *timeout)
 Specify timeout for the pipe I/O. More...
 
const STimeoutGetTimeout (EIO_Event event) const
 Get pipe I/O timeout. More...
 
TProcessHandle GetProcessHandle (void) const
 Get the process handle for the piped child. More...
 

Static Public Member Functions

static EFinish ExecWait (const string &cmd, const vector< string > &args, CNcbiIstream &in, CNcbiOstream &out, CNcbiOstream &err, int &exit_code, const string &current_dir=kEmptyStr, const char *const envp[]=0, IProcessWatcher *watcher=0, const STimeout *kill_timeout=0, size_t pipe_size=0)
 Execute a command with a vector of arguments, and wait for its completion. More...
 

Protected Attributes

size_t m_PipeSize
 Pipe size. More...
 
CPipeHandlem_PipeHandle
 Internal OS-specific pipe handle. More...
 
EChildIOHandle m_ReadHandle
 Default handle used for read. More...
 
EIO_Status m_ReadStatus
 Last read status. More...
 
EIO_Status m_WriteStatus
 Last write status. More...
 
const STimeoutm_ReadTimeout
 eIO_Read timeout More...
 
const STimeoutm_WriteTimeout
 eIO_Write timeout More...
 
const STimeoutm_CloseTimeout
 eIO_Close timeout More...
 
STimeout m_ReadTimeoutValue
 Storage for m_ReadTimeout. More...
 
STimeout m_WriteTimeoutValue
 Storage for m_WriteTimeout. More...
 
STimeout m_CloseTimeoutValue
 Storage for m_CloseTimeout. More...
 

Private Member Functions

 CPipe (const CPipe &)
 
CPipeoperator= (const CPipe &)
 

Additional Inherited Members

- Protected Member Functions inherited from CConnIniter
 CConnIniter (void)
 

Detailed Description

CPipe –.

Spawn a child process (command) with pipes attached to its standard I/O.

The application can then read from stdout/stderr and write to stdin of the launched child process using the Read / Write methods of the pipe object.

See also
CNamedPipe, CExec

Definition at line 75 of file ncbi_pipe.hpp.


The documentation for this class was generated from the following files:
Modified on Wed Apr 17 13:10:39 2024 by modify_doxy.py rev. 669887