30 #ifndef REDI_PSTREAM_H_SEEN 31 #define REDI_PSTREAM_H_SEEN 43 #include <sys/types.h> 45 #include <sys/ioctl.h> 47 # include <sys/filio.h> 52 #if REDI_EVISCERATE_PSTREAMS 58 #define PSTREAMS_VERSION 0x0081 // 0.8.1 79 typedef std::ios_base::openmode
pmode;
100 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
102 :
public std::basic_streambuf<CharT, Traits>
107 typedef CharT char_type;
108 typedef Traits traits_type;
109 typedef typename traits_type::int_type int_type;
110 typedef typename traits_type::off_type off_type;
111 typedef typename traits_type::pos_type pos_type;
131 open(
const std::string& command,
pmode mode);
143 kill(
int signal = SIGTERM);
147 killpg(
int signal = SIGTERM);
165 #if REDI_EVISCERATE_PSTREAMS 168 fopen(FILE*& in, FILE*& out, FILE*& err);
190 pbackfail(int_type c = traits_type::eof());
198 xsputn(
const char_type* s, std::streamsize n);
202 write(
const char_type* s, std::streamsize n);
206 read(char_type* s, std::streamsize n);
222 wait(
bool nohang =
false);
237 create_buffers(
pmode mode);
240 destroy_buffers(
pmode mode);
267 char_type* rbuffer_[2];
268 char_type* rbufstate_[3];
276 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
278 :
virtual public std::basic_ios<CharT, Traits>
325 #if REDI_EVISCERATE_PSTREAMS 328 fopen(FILE*& in, FILE*& out, FILE*& err);
347 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
349 :
public std::basic_istream<CharT, Traits>
353 typedef std::basic_istream<CharT, Traits> istream_type;
368 typedef typename pbase_type::pmode
pmode;
407 : istream_type(NULL),
pbase_type(file, argv, readable(mode))
422 : istream_type(NULL),
pbase_type(argv.at(0), argv, readable(mode))
425 #if __cplusplus >= 201103L 453 this->
do_open(command, readable(mode));
471 this->
do_open(file, argv, readable(mode));
507 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
509 :
public std::basic_ostream<CharT, Traits>
513 typedef std::basic_ostream<CharT, Traits> ostream_type;
520 typedef typename pbase_type::pmode
pmode;
577 #if __cplusplus >= 201103L 647 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
649 :
public std::basic_iostream<CharT, Traits>
653 typedef std::basic_iostream<CharT, Traits> iostream_type;
660 typedef typename pbase_type::pmode
pmode;
699 : iostream_type(NULL),
pbase_type(file, argv, mode)
714 : iostream_type(NULL),
pbase_type(argv.at(0), argv, mode)
717 #if __cplusplus >= 201103L 769 this->
do_open(file, argv, mode);
817 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
819 :
public std::basic_ostream<CharT, Traits>
820 ,
private std::basic_istream<CharT, Traits>
824 typedef std::basic_ostream<CharT, Traits> ostream_type;
825 typedef std::basic_istream<CharT, Traits> istream_type;
832 typedef typename pbase_type::pmode
pmode;
839 : ostream_type(NULL), istream_type(NULL),
pbase_type()
871 : ostream_type(NULL), istream_type(NULL),
pbase_type(file, argv, mode)
886 : ostream_type(NULL), istream_type(NULL),
890 #if __cplusplus >= 201103L 938 this->
do_open(file, argv, mode);
991 template <
typename C,
typename T>
992 inline std::basic_ostream<C,T>&
993 peof(std::basic_ostream<C,T>& s)
996 if (
pstreambuf* p = dynamic_cast<pstreambuf*>(s.rdbuf()))
1013 template <
typename C,
typename T>
1034 template <
typename C,
typename T>
1045 open(command, mode);
1057 template <
typename C,
typename T>
1070 open(file, argv, mode);
1077 template <
typename C,
typename T>
1111 template <
typename C,
typename T>
1115 const char * shell_path =
"/bin/sh";
1117 const std::string argv[] = {
"sh",
"-c", command };
1118 return this->open(shell_path,
argv_type(argv, argv+3), mode);
1128 ::execl(shell_path,
"sh",
"-c", command.c_str(), (
char*)NULL);
1143 create_buffers(mode);
1162 if (fd >= 0 && ::close(fd) == 0)
1180 for (std::size_t i = 0; i < N; ++i)
1213 template <
typename C,
typename T>
1227 fd_type ck_exec[] = { -1, -1 };
1228 if (-1 == ::pipe(ck_exec)
1229 || -1 == ::fcntl(ck_exec[RD], F_SETFD, FD_CLOEXEC)
1230 || -1 == ::fcntl(ck_exec[WR], F_SETFD, FD_CLOEXEC))
1233 close_fd_array(ck_exec);
1242 char** arg_v =
new char*[argv.size()+1];
1243 for (std::size_t i = 0; i < argv.size(); ++i)
1245 const std::string& src = argv[i];
1246 char*& dest = arg_v[i];
1247 dest =
new char[src.size()+1];
1248 dest[ src.copy(dest, src.size()) ] =
'\0';
1250 arg_v[argv.size()] = NULL;
1252 ::execvp(file.c_str(), arg_v);
1259 while (::write(ck_exec[WR], &error_,
sizeof(error_)) == -1
1263 ::close(ck_exec[WR]);
1264 ::close(ck_exec[RD]);
1272 close_fd_array(ck_exec);
1279 ::close(ck_exec[WR]);
1280 switch (::read(ck_exec[RD], &error_,
sizeof(error_)))
1284 create_buffers(mode);
1296 ::close(ck_exec[RD]);
1319 template <
typename C,
typename T>
1328 fd_type fd[] = { -1, -1, -1, -1, -1, -1 };
1329 fd_type*
const pin = fd;
1330 fd_type*
const pout = fd+2;
1331 fd_type*
const perr = fd+4;
1340 if (!error_ && mode&pstdin && ::pipe(pin))
1343 if (!error_ && mode&pstdout && ::pipe(pout))
1346 if (!error_ && mode&pstderr && ::pipe(perr))
1364 ::dup2(pin[RD], STDIN_FILENO);
1370 ::dup2(pout[WR], STDOUT_FILENO);
1376 ::dup2(perr[WR], STDERR_FILENO);
1380 #ifdef _POSIX_JOB_CONTROL 1408 rpipe_[rsrc_out] = pout[RD];
1413 rpipe_[rsrc_err] = perr[RD];
1436 template <
typename C,
typename T>
1440 const bool running = is_open();
1447 destroy_buffers(pstdin|pstdout|pstderr);
1451 close_fd_array(rpipe_);
1456 }
while (wait() == -1 && error() == EINTR);
1458 return running ? this : NULL;
1464 template <
typename C,
typename T>
1468 rpipe_[rsrc_out] = rpipe_[rsrc_err] = -1;
1469 rbuffer_[rsrc_out] = rbuffer_[rsrc_err] = NULL;
1470 rbufstate_[0] = rbufstate_[1] = rbufstate_[2] = NULL;
1473 template <
typename C,
typename T>
1475 basic_pstreambuf<C,T>::create_buffers(pmode mode)
1480 wbuffer_ =
new char_type[bufsz];
1481 this->setp(wbuffer_, wbuffer_ + bufsz);
1485 delete[] rbuffer_[rsrc_out];
1486 rbuffer_[rsrc_out] =
new char_type[bufsz];
1488 this->setg(rbuffer_[rsrc_out] + pbsz, rbuffer_[rsrc_out] + pbsz,
1489 rbuffer_[rsrc_out] + pbsz);
1493 delete[] rbuffer_[rsrc_err];
1494 rbuffer_[rsrc_err] =
new char_type[bufsz];
1495 if (!(mode & pstdout))
1498 this->setg(rbuffer_[rsrc_err] + pbsz, rbuffer_[rsrc_err] + pbsz,
1499 rbuffer_[rsrc_err] + pbsz);
1504 template <
typename C,
typename T>
1506 basic_pstreambuf<C,T>::destroy_buffers(pmode mode)
1510 this->setp(NULL, NULL);
1516 if (rsrc_ == rsrc_out)
1517 this->setg(NULL, NULL, NULL);
1518 delete[] rbuffer_[rsrc_out];
1519 rbuffer_[rsrc_out] = NULL;
1523 if (rsrc_ == rsrc_err)
1524 this->setg(NULL, NULL, NULL);
1525 delete[] rbuffer_[rsrc_err];
1526 rbuffer_[rsrc_err] = NULL;
1530 template <
typename C,
typename T>
1532 basic_pstreambuf<C,T>::switch_read_buffer(buf_read_src src)
1536 char_type* tmpbufstate[] = {this->eback(), this->gptr(), this->egptr()};
1537 this->setg(rbufstate_[0], rbufstate_[1], rbufstate_[2]);
1538 for (std::size_t i = 0; i < 3; ++i)
1539 rbufstate_[i] = tmpbufstate[i];
1561 template <
typename C,
typename T>
1569 switch(::waitpid(ppid_, &status, nohang ? WNOHANG : 0))
1584 destroy_buffers(pstdin);
1604 template <
typename C,
typename T>
1611 if (::kill(ppid_, signal))
1617 if (signal==SIGTERM || signal==SIGKILL)
1639 template <
typename C,
typename T>
1644 #ifdef _POSIX_JOB_CONTROL 1647 pid_t pgid = ::getpgid(ppid_);
1650 else if (pgid == ::getpgrp())
1652 else if (::killpg(pgid, signal))
1670 template <
typename C,
typename T>
1674 return ppid_ == 0 || wait(
true)==1;
1683 template <
typename C,
typename T>
1693 template <
typename C,
typename T>
1704 template <
typename C,
typename T>
1709 destroy_buffers(pstdin);
1723 template <
typename C,
typename T>
1738 template <
typename C,
typename T>
1745 switch_read_buffer(src);
1761 template <
typename C,
typename T>
1762 typename basic_pstreambuf<C,T>::int_type
1765 if (!empty_buffer())
1766 return traits_type::eof();
1767 else if (!traits_type::eq_int_type(c, traits_type::eof()))
1768 return this->sputc(c);
1770 return traits_type::not_eof(c);
1774 template <
typename C,
typename T>
1778 return !exited() && empty_buffer() ? 0 : -1;
1786 template <
typename C,
typename T>
1790 std::streamsize done = 0;
1793 if (std::streamsize nbuf = this->epptr() - this->pptr())
1795 nbuf = std::min(nbuf, n - done);
1796 traits_type::copy(this->pptr(), s + done, nbuf);
1800 else if (!empty_buffer())
1809 template <
typename C,
typename T>
1813 const std::streamsize count = this->pptr() - this->pbase();
1816 const std::streamsize written = this->write(this->wbuffer_, count);
1819 if (
const std::streamsize unwritten = count - written)
1820 traits_type::move(this->pbase(), this->pbase()+written, unwritten);
1821 this->pbump(-written);
1835 template <
typename C,
typename T>
1836 typename basic_pstreambuf<C,T>::int_type
1839 if (this->gptr() < this->egptr() || fill_buffer())
1840 return traits_type::to_int_type(*this->gptr());
1842 return traits_type::eof();
1853 template <
typename C,
typename T>
1854 typename basic_pstreambuf<C,T>::int_type
1857 if (this->gptr() != this->eback())
1860 if (!traits_type::eq_int_type(c, traits_type::eof()))
1861 *this->gptr() = traits_type::to_char_type(c);
1862 return traits_type::not_eof(c);
1865 return traits_type::eof();
1868 template <
typename C,
typename T>
1873 if (
sizeof(char_type) == 1)
1874 avail = fill_buffer(
true) ? this->egptr() - this->gptr() : -1;
1878 if (::ioctl(rpipe(), FIONREAD, &avail) == -1)
1881 avail /=
sizeof(char_type);
1884 return std::streamsize(avail);
1890 template <
typename C,
typename T>
1894 const std::streamsize pb1 = this->gptr() - this->eback();
1895 const std::streamsize pb2 = pbsz;
1896 const std::streamsize npb = std::min(pb1, pb2);
1898 char_type*
const rbuf = rbuffer();
1900 traits_type::move(rbuf + pbsz - npb, this->gptr() - npb, npb);
1902 std::streamsize rc = -1;
1906 const int flags = ::fcntl(rpipe(), F_GETFL);
1909 const bool blocking = !(flags & O_NONBLOCK);
1911 ::fcntl(rpipe(), F_SETFL, flags | O_NONBLOCK);
1914 rc = read(rbuf + pbsz, bufsz - pbsz);
1916 if (rc == -1 && error_ == EAGAIN)
1922 ::fcntl(rpipe(), F_SETFL, flags);
1926 rc = read(rbuf + pbsz, bufsz - pbsz);
1928 if (rc > 0 || (rc == 0 && non_blocking))
1930 this->setg( rbuf + pbsz - npb,
1937 this->setg(NULL, NULL, NULL);
1949 template <
typename C,
typename T>
1950 inline std::streamsize
1953 std::streamsize nwritten = 0;
1956 nwritten = ::write(wpipe(), s, n *
sizeof(char_type));
1960 nwritten /=
sizeof(char_type);
1972 template <
typename C,
typename T>
1973 inline std::streamsize
1976 std::streamsize nread = 0;
1979 nread = ::read(rpipe(), s, n *
sizeof(char_type));
1983 nread /=
sizeof(char_type);
1989 template <
typename C,
typename T>
1997 template <
typename C,
typename T>
2001 return rpipe_[rsrc_];
2005 template <
typename C,
typename T>
2009 return rpipe_[which];
2013 template <
typename C,
typename T>
2014 inline typename basic_pstreambuf<C,T>::char_type*
2017 return rbuffer_[rsrc_];
2034 template <
typename C,
typename T>
2037 : std::basic_ios<C,T>(NULL)
2041 this->std::basic_ios<C,T>::rdbuf(&
buf_);
2052 template <
typename C,
typename T>
2055 : std::basic_ios<C,T>(NULL)
2059 this->std::basic_ios<C,T>::rdbuf(&
buf_);
2072 template <
typename C,
typename T>
2077 : std::basic_ios<C,T>(NULL)
2081 this->std::basic_ios<C,T>::rdbuf(&
buf_);
2094 template <
typename C,
typename T>
2108 template <
typename C,
typename T>
2112 if (!buf_.open((command_=command), mode))
2113 this->setstate(std::ios_base::failbit);
2125 template <
typename C,
typename T>
2131 if (!buf_.open((command_=file), argv, mode))
2132 this->setstate(std::ios_base::failbit);
2136 template <
typename C,
typename T>
2141 this->setstate(std::ios_base::failbit);
2148 template <
typename C,
typename T>
2152 return buf_.is_open();
2156 template <
typename C,
typename T>
2157 inline const std::string&
2165 template <
typename C,
typename T>
2169 return const_cast<streambuf_type*>(&buf_);
2173 #if REDI_EVISCERATE_PSTREAMS 2206 template <
typename C,
typename T>
2210 in = out = err = NULL;
2211 std::size_t open_files = 0;
2214 if ((in = ::fdopen(wpipe(),
"w")))
2216 open_files |= pstdin;
2219 if (rpipe(rsrc_out) > -1)
2221 if ((out = ::fdopen(rpipe(rsrc_out),
"r")))
2223 open_files |= pstdout;
2226 if (rpipe(rsrc_err) > -1)
2228 if ((err = ::fdopen(rpipe(rsrc_err),
"r")))
2230 open_files |= pstderr;
2246 template <
typename C,
typename T>
2248 pstream_common<C,T>::fopen(FILE*& fin, FILE*& fout, FILE*& ferr)
2250 return buf_.fopen(fin, fout, ferr);
2253 #endif // REDI_EVISCERATE_PSTREAMS 2263 #endif // REDI_PSTREAM_H_SEEN void close_fd(pstreams::fd_type &fd)
Helper function to close a file descriptor.
Definition: pstream.h:1160
basic_pstream(const std::string &command, pmode mode=pstdout|pstdin)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:681
int_type overflow(int_type c)
Transfer characters to the pipe when character buffer overflows.
Definition: pstream.h:1763
std::streamsize write(const char_type *s, std::streamsize n)
Insert a sequence of characters into the pipe.
Definition: pstream.h:1951
pbase_type::argv_type argv_type
Type used to hold the arguments for a command.
Definition: pstream.h:835
fd_type fd_t
Definition: pstream.h:113
~basic_pstream()
Destructor.
Definition: pstream.h:737
fd_type & wpipe()
Return the file descriptor for the output pipe.
Definition: pstream.h:1991
Class template for Bidirectional PStreams.
Definition: pstream.h:648
char_type * rbuffer()
Return the active input buffer.
Definition: pstream.h:2015
Class template for stream buffer.
Definition: pstream.h:101
pbase_type::pmode pmode
Type used to specify how to connect to the process.
Definition: pstream.h:368
bool is_open() const
Report whether the stream buffer has been initialised.
Definition: pstream.h:1725
std::streamsize read(char_type *s, std::streamsize n)
Extract a sequence of characters from the pipe.
Definition: pstream.h:1974
basic_rpstream()
Default constructor, creates an uninitialised stream.
Definition: pstream.h:838
void open(const std::string &command, pmode mode=pstdout|pstdin)
Start a process.
Definition: pstream.h:918
basic_pstream()
Default constructor, creates an uninitialised stream.
Definition: pstream.h:666
int error() const
Return the error number (errno) for the most recent failed operation.
Definition: pstream.h:1695
pbase_type::pmode pmode
Type used to specify how to connect to the process.
Definition: pstream.h:520
const std::string & command() const
Return the command used to initialise the stream.
Definition: pstream.h:2158
bool read_err(bool readerr=true)
Change active input source.
Definition: pstream.h:1740
basic_rpstream(const std::string &command, pmode mode=pstdout|pstdin)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:853
virtual ~pstream_common()=0
Pure virtual destructor.
Definition: pstream.h:2096
void close_fd_array(pstreams::fd_type(&fds)[N])
Helper function to close an array of file descriptors.
Definition: pstream.h:1178
std::vector< std::string > argv_type
Type used to hold the arguments for a command.
Definition: pstream.h:82
pbase_type::argv_type argv_type
Type used to hold the arguments for a command.
Definition: pstream.h:371
pstream_common()
Default constructor.
Definition: pstream.h:2036
int_type underflow()
Transfer characters from the pipe when the character buffer is empty.
Definition: pstream.h:1837
void open(const std::string &file, const argv_type &argv, pmode mode=pstdout|pstdin)
Start a process.
Definition: pstream.h:934
Class template for common base class.
Definition: pstream.h:277
basic_rpstream(const argv_type &argv, pmode mode=pstdout|pstdin)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:885
basic_ipstream(const argv_type &argv, pmode mode=pstdout)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:421
basic_pstream(const std::string &file, const argv_type &argv, pmode mode=pstdout|pstdin)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:696
basic_opstream()
Default constructor, creates an uninitialised stream.
Definition: pstream.h:526
basic_pstreambuf< char > pstreambuf
Type definition for common template specialisation.
Definition: pstream.h:968
static const pmode pstderr
Read from stderr.
Definition: pstream.h:89
int status() const
Return the exit status of the process.
Definition: pstream.h:1685
int_type pbackfail(int_type c=traits_type::eof())
Make a character available to be returned by the next extraction.
Definition: pstream.h:1855
Common base class providing constants and typenames.
Definition: pstream.h:76
bool fill_buffer(bool non_blocking=false)
Definition: pstream.h:1892
static const pmode pstdout
Read from stdout.
Definition: pstream.h:88
int sync()
Write any buffered characters to the stream.
Definition: pstream.h:1776
basic_rpstream(const std::string &file, const argv_type &argv, pmode mode=pstdout|pstdin)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:868
basic_pstreambuf()
Default constructor.
Definition: pstream.h:1015
basic_ipstream(const std::string &command, pmode mode=pstdout)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:389
std::string command_
The command used to start the process.
Definition: pstream.h:332
bool exited()
Report whether the process has exited.
Definition: pstream.h:1672
bool is_open() const
Report whether the stream's buffer has been initialised.
Definition: pstream.h:2150
streambuf_type buf_
The stream buffer.
Definition: pstream.h:333
buf_read_src
Enumerated type to indicate whether stdout or stderr is to be read.
Definition: pstream.h:214
basic_pstream & out()
Set streambuf to read from process' stdout.
Definition: pstream.h:777
basic_ipstream(const std::string &file, const argv_type &argv, pmode mode=pstdout)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:404
Class template for Input PStreams.
Definition: pstream.h:348
pbase_type::argv_type argv_type
Type used to hold the arguments for a command.
Definition: pstream.h:663
std::streamsize xsputn(const char_type *s, std::streamsize n)
Insert multiple characters into the pipe.
Definition: pstream.h:1788
void open(const std::string &command, pmode mode=pstdin)
Start a process.
Definition: pstream.h:609
pid_t fork(pmode mode)
Initialise pipes and fork process.
Definition: pstream.h:1321
basic_ipstream & err()
Set streambuf to read from process' stderr.
Definition: pstream.h:490
basic_pstream & err()
Set streambuf to read from process' stderr.
Definition: pstream.h:788
basic_opstream(const argv_type &argv, pmode mode=pstdin)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:573
basic_rpstream< char > rpstream
Type definition for common template specialisation.
Definition: pstream.h:976
basic_ipstream & out()
Set streambuf to read from process' stdout.
Definition: pstream.h:479
void open(const std::string &command, pmode mode=pstdout|pstdin)
Start a process.
Definition: pstream.h:749
pbase_type::argv_type argv_type
Type used to hold the arguments for a command.
Definition: pstream.h:523
All PStreams classes are declared in namespace redi.
int fd_type
Type used for file descriptors.
Definition: pstream.h:85
streambuf_type * rdbuf() const
Return a pointer to the stream buffer.
Definition: pstream.h:2167
~basic_pstreambuf()
Destructor.
Definition: pstream.h:1079
basic_pstream(const argv_type &argv, pmode mode=pstdout|pstdin)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:713
std::ios_base::openmode pmode
Type used to specify how to connect to the process.
Definition: pstream.h:79
Class template for Restricted PStreams.
Definition: pstream.h:818
basic_pstreambuf * killpg(int signal=SIGTERM)
Send a signal to the process' process group.
Definition: pstream.h:1641
basic_pstreambuf * close()
Close the stream buffer and wait for the process to exit.
Definition: pstream.h:1438
bool empty_buffer()
Writes buffered characters to the process' stdin pipe.
Definition: pstream.h:1811
void do_open(const std::string &command, pmode mode)
Start a process.
Definition: pstream.h:2110
~basic_ipstream()
Destructor.
Definition: pstream.h:438
pbase_type::pmode pmode
Type used to specify how to connect to the process.
Definition: pstream.h:832
std::basic_ostream< C, T > & peof(std::basic_ostream< C, T > &s)
Manipulator to close the pipe connected to the process' stdin.
Definition: pstream.h:993
basic_ipstream< char > ipstream
Type definition for common template specialisation.
Definition: pstream.h:970
void open(const std::string &command, pmode mode=pstdout)
Start a process.
Definition: pstream.h:451
int wait(bool nohang=false)
Wait for the child process to exit.
Definition: pstream.h:1563
void open(const std::string &file, const argv_type &argv, pmode mode=pstdout)
Start a process.
Definition: pstream.h:467
Class template for Output PStreams.
Definition: pstream.h:508
static const pmode newpg
Create a new process group for the child process.
Definition: pstream.h:92
basic_pstreambuf * open(const std::string &command, pmode mode)
Initialise the stream buffer with command.
Definition: pstream.h:1113
fd_type & rpipe()
Return the file descriptor for the active input pipe.
Definition: pstream.h:1999
istream_type & err()
Obtain a reference to the istream that reads the process' stderr.
Definition: pstream.h:959
basic_ipstream()
Default constructor, creates an uninitialised stream.
Definition: pstream.h:374
~basic_rpstream()
Destructor.
Definition: pstream.h:906
void close()
Close the pipe.
Definition: pstream.h:2138
void peof()
Close the pipe connected to the process' stdin.
Definition: pstream.h:1706
basic_opstream< char > opstream
Type definition for common template specialisation.
Definition: pstream.h:972
pbase_type::pmode pmode
Type used to specify how to connect to the process.
Definition: pstream.h:660
void open(const std::string &file, const argv_type &argv, pmode mode=pstdin)
Start a process.
Definition: pstream.h:625
basic_pstream< char > pstream
Type definition for common template specialisation.
Definition: pstream.h:974
static const pmode pstdin
Write to stdin.
Definition: pstream.h:87
std::streamsize showmanyc()
Report how many characters can be read from active input without blocking.
Definition: pstream.h:1870
void open(const std::string &file, const argv_type &argv, pmode mode=pstdout|pstdin)
Start a process.
Definition: pstream.h:765
basic_opstream(const std::string &file, const argv_type &argv, pmode mode=pstdin)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:556
basic_opstream(const std::string &command, pmode mode=pstdin)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:541
basic_pstreambuf * kill(int signal=SIGTERM)
Send a signal to the process.
Definition: pstream.h:1606
istream_type & out()
Obtain a reference to the istream that reads the process' stdout.
Definition: pstream.h:947
~basic_opstream()
Destructor.
Definition: pstream.h:597