The GNU C++ Iostream Library



5.5: Reading/writing from/to a pipe

The procbuf class is a GNU extension. It is derived from streambuf. A procbuf can be closed (in which case it does nothing), or open (in which case it allows communicating through a pipe with some other program).


Constructor:  procbuf::procbuf ()

Creates a procbuf in a closed state.

Method:  procbuf* procbuf::open (const char *command, int mode)

Uses the shell ( /bin/sh) to run a program specified by command.

If mode is `ios::in', standard output from the program is sent to a pipe; you can read from the pipe by reading from the procbuf. (This is similar to `popen(command, "r")'.)

If mode is `ios::out', output written written to the procbuf is written to a pipe; the program is set up to read its standard input from (the other end of) the pipe. (This is similar to `popen(command, "w")'.)

The procbuf must start out in the closed state. Returns `*this' on success, and `NULL' on failure.


Constructor:  procbuf::procbuf (const char *command, int mode)

Calls `procbuf::open (command, mode)'.

Method:  procbuf* procbuf::close ()

Waits for the program to finish executing, and then cleans up the resources used. Returns `*this' on success, and `NULL' on failure.

Destructor:  procbuf::~procbuf ()

Calls `procbuf::close'.


Translated 02/24/96 by Rance Necaise. Original texi file by Bothner and Pesch.