18 #ifndef REDI_PSTREAM_H_SEEN 19 #define REDI_PSTREAM_H_SEEN 31 #include <sys/types.h> 33 #include <sys/ioctl.h> 35 # include <sys/filio.h> 40 #if REDI_EVISCERATE_PSTREAMS 46 #define PSTREAMS_VERSION 0x0101 // 1.0.1 67 typedef std::ios_base::openmode
pmode;
75 static const pmode
pstdin = std::ios_base::out;
76 static const pmode
pstdout = std::ios_base::in;
77 static const pmode
pstderr = std::ios_base::app;
80 static const pmode
newpg = std::ios_base::trunc;
88 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
90 :
public std::basic_streambuf<CharT, Traits>
95 typedef CharT char_type;
96 typedef Traits traits_type;
97 typedef typename traits_type::int_type int_type;
98 typedef typename traits_type::off_type off_type;
99 typedef typename traits_type::pos_type pos_type;
119 open(
const std::string& cmd,
pmode mode);
131 kill(
int signal = SIGTERM);
135 killpg(
int signal = SIGTERM);
143 read_err(
bool readerr =
true);
153 #if REDI_EVISCERATE_PSTREAMS 156 fopen(FILE*& in, FILE*& out, FILE*& err);
170 overflow(int_type c);
178 pbackfail(int_type c = traits_type::eof());
186 xsputn(
const char_type* s, std::streamsize n);
190 write(
const char_type* s, std::streamsize n);
194 read(char_type* s, std::streamsize n);
210 wait(
bool nohang =
false);
225 create_buffers(
pmode mode);
228 destroy_buffers(
pmode mode);
235 fill_buffer(
bool non_blocking =
false);
255 char_type* rbuffer_[2];
256 char_type* rbufstate_[3];
264 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
266 :
virtual public std::basic_ios<CharT, Traits>
282 pstream_common(
const std::string& file,
const argv_type& argv, pmode mode);
290 do_open(
const std::string& cmd, pmode mode);
294 do_open(
const std::string& file,
const argv_type& argv, pmode mode);
313 #if REDI_EVISCERATE_PSTREAMS 316 fopen(FILE*& in, FILE*& out, FILE*& err);
335 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
337 :
public std::basic_istream<CharT, Traits>
341 typedef std::basic_istream<CharT, Traits> istream_type;
344 using pbase_type::buf_;
356 typedef typename pbase_type::pmode
pmode;
363 : istream_type(NULL), pbase_type()
378 : istream_type(NULL), pbase_type(cmd, readable(mode))
393 const argv_type& argv,
395 : istream_type(NULL), pbase_type(file, argv, readable(mode))
410 : istream_type(NULL), pbase_type(argv.at(0), argv, readable(mode))
413 #if __cplusplus >= 201103L 441 this->do_open(cmd, readable(mode));
456 const argv_type& argv,
459 this->do_open(file, argv, readable(mode));
469 this->buf_.read_err(
false);
480 this->buf_.read_err(
true);
495 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
497 :
public std::basic_ostream<CharT, Traits>
501 typedef std::basic_ostream<CharT, Traits> ostream_type;
504 using pbase_type::buf_;
508 typedef typename pbase_type::pmode
pmode;
515 : ostream_type(NULL), pbase_type()
530 : ostream_type(NULL), pbase_type(cmd, mode|
pstdin)
545 const argv_type& argv,
547 : ostream_type(NULL), pbase_type(file, argv, mode|
pstdin)
562 : ostream_type(NULL), pbase_type(argv.at(0), argv, mode|
pstdin)
565 #if __cplusplus >= 201103L 599 this->do_open(cmd, mode|
pstdin);
614 const argv_type& argv,
617 this->do_open(file, argv, mode|
pstdin);
635 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
637 :
public std::basic_iostream<CharT, Traits>
641 typedef std::basic_iostream<CharT, Traits> iostream_type;
644 using pbase_type::buf_;
648 typedef typename pbase_type::pmode
pmode;
655 : iostream_type(NULL), pbase_type()
670 : iostream_type(NULL), pbase_type(cmd, mode)
685 const argv_type& argv,
687 : iostream_type(NULL), pbase_type(file, argv, mode)
702 : iostream_type(NULL), pbase_type(argv.at(0), argv, mode)
705 #if __cplusplus >= 201103L 739 this->do_open(cmd, mode);
754 const argv_type& argv,
757 this->do_open(file, argv, mode);
767 this->buf_.read_err(
false);
778 this->buf_.read_err(
true);
805 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
807 :
public std::basic_ostream<CharT, Traits>
808 ,
private std::basic_istream<CharT, Traits>
812 typedef std::basic_ostream<CharT, Traits> ostream_type;
813 typedef std::basic_istream<CharT, Traits> istream_type;
816 using pbase_type::buf_;
820 typedef typename pbase_type::pmode
pmode;
827 : ostream_type(NULL), istream_type(NULL), pbase_type()
842 : ostream_type(NULL) , istream_type(NULL) , pbase_type(cmd, mode)
857 const argv_type& argv,
859 : ostream_type(NULL), istream_type(NULL), pbase_type(file, argv, mode)
874 : ostream_type(NULL), istream_type(NULL),
875 pbase_type(argv.at(0), argv, mode)
878 #if __cplusplus >= 201103L 908 this->do_open(cmd, mode);
923 const argv_type& argv,
926 this->do_open(file, argv, mode);
937 this->buf_.read_err(
false);
949 this->buf_.read_err(
true);
979 template <
typename C,
typename T>
980 inline std::basic_ostream<C,T>&
981 peof(std::basic_ostream<C,T>& s)
984 if (pstreambuf_type* p = dynamic_cast<pstreambuf_type*>(s.rdbuf()))
1001 template <
typename C,
typename T>
1022 template <
typename C,
typename T>
1045 template <
typename C,
typename T>
1058 open(file, argv, mode);
1065 template <
typename C,
typename T>
1099 template <
typename C,
typename T>
1103 const char * shell_path =
"/bin/sh";
1105 const std::string argv[] = {
"sh",
"-c", command };
1106 return this->
open(shell_path,
argv_type(argv, argv+3), mode);
1116 ::execl(shell_path,
"sh",
"-c", command.c_str(), (
char*)NULL);
1131 create_buffers(mode);
1150 if (fd >= 0 && ::
close(fd) == 0)
1168 for (std::size_t i = 0; i < N; ++i)
1201 template <
typename C,
typename T>
1215 fd_type ck_exec[] = { -1, -1 };
1216 if (-1 == ::pipe(ck_exec)
1217 || -1 == ::fcntl(ck_exec[RD], F_SETFD, FD_CLOEXEC)
1218 || -1 == ::fcntl(ck_exec[WR], F_SETFD, FD_CLOEXEC))
1230 char** arg_v =
new char*[argv.size()+1];
1231 for (std::size_t i = 0; i < argv.size(); ++i)
1233 const std::string& src = argv[i];
1234 char*& dest = arg_v[i];
1235 dest =
new char[src.size()+1];
1236 dest[ src.copy(dest, src.size()) ] =
'\0';
1238 arg_v[argv.size()] = NULL;
1240 ::execvp(file.c_str(), arg_v);
1247 while (::
write(ck_exec[WR], &error_,
sizeof(error_)) == -1
1268 switch (::
read(ck_exec[RD], &error_,
sizeof(error_)))
1272 create_buffers(mode);
1307 template <
typename C,
typename T>
1316 fd_type fd[] = { -1, -1, -1, -1, -1, -1 };
1328 if (!error_ && mode&
pstdin && ::pipe(pin))
1331 if (!error_ && mode&
pstdout && ::pipe(pout))
1334 if (!error_ && mode&
pstderr && ::pipe(perr))
1352 ::dup2(pin[RD], STDIN_FILENO);
1358 ::dup2(pout[WR], STDOUT_FILENO);
1364 ::dup2(perr[WR], STDERR_FILENO);
1368 #ifdef _POSIX_JOB_CONTROL 1396 rpipe_[rsrc_out] = pout[RD];
1401 rpipe_[rsrc_err] = perr[RD];
1424 template <
typename C,
typename T>
1428 const bool running =
is_open();
1444 }
while (
wait() == -1 &&
error() == EINTR);
1446 return running ? this : NULL;
1452 template <
typename C,
typename T>
1456 rpipe_[rsrc_out] = rpipe_[rsrc_err] = -1;
1457 rbuffer_[rsrc_out] = rbuffer_[rsrc_err] = NULL;
1458 rbufstate_[0] = rbufstate_[1] = rbufstate_[2] = NULL;
1461 template <
typename C,
typename T>
1468 wbuffer_ =
new char_type[bufsz];
1469 this->setp(wbuffer_, wbuffer_ + bufsz);
1473 delete[] rbuffer_[rsrc_out];
1474 rbuffer_[rsrc_out] =
new char_type[bufsz];
1476 this->setg(rbuffer_[rsrc_out] + pbsz, rbuffer_[rsrc_out] + pbsz,
1477 rbuffer_[rsrc_out] + pbsz);
1481 delete[] rbuffer_[rsrc_err];
1482 rbuffer_[rsrc_err] =
new char_type[bufsz];
1483 if (!(mode & pstdout))
1486 this->setg(rbuffer_[rsrc_err] + pbsz, rbuffer_[rsrc_err] + pbsz,
1487 rbuffer_[rsrc_err] + pbsz);
1492 template <
typename C,
typename T>
1498 this->setp(NULL, NULL);
1504 if (rsrc_ == rsrc_out)
1505 this->setg(NULL, NULL, NULL);
1506 delete[] rbuffer_[rsrc_out];
1507 rbuffer_[rsrc_out] = NULL;
1511 if (rsrc_ == rsrc_err)
1512 this->setg(NULL, NULL, NULL);
1513 delete[] rbuffer_[rsrc_err];
1514 rbuffer_[rsrc_err] = NULL;
1518 template <
typename C,
typename T>
1524 char_type* tmpbufstate[] = {this->eback(), this->gptr(), this->egptr()};
1525 this->setg(rbufstate_[0], rbufstate_[1], rbufstate_[2]);
1526 for (std::size_t i = 0; i < 3; ++i)
1527 rbufstate_[i] = tmpbufstate[i];
1549 template <
typename C,
typename T>
1553 int child_exited = -1;
1557 switch(::waitpid(ppid_, &exit_status, nohang ? WNOHANG : 0))
1569 status_ = exit_status;
1579 return child_exited;
1592 template <
typename C,
typename T>
1599 if (::
kill(ppid_, signal))
1605 if (signal==SIGTERM || signal==SIGKILL)
1627 template <
typename C,
typename T>
1632 #ifdef _POSIX_JOB_CONTROL 1635 pid_t pgid = ::getpgid(ppid_);
1638 else if (pgid == ::getpgrp())
1640 else if (::
killpg(pgid, signal))
1658 template <
typename C,
typename T>
1662 return ppid_ == 0 ||
wait(
true)==1;
1671 template <
typename C,
typename T>
1681 template <
typename C,
typename T>
1692 template <
typename C,
typename T>
1711 template <
typename C,
typename T>
1726 template <
typename C,
typename T>
1733 switch_read_buffer(src);
1749 template <
typename C,
typename T>
1750 typename basic_pstreambuf<C,T>::int_type
1754 return traits_type::eof();
1755 else if (!traits_type::eq_int_type(c, traits_type::eof()))
1756 return this->sputc(c);
1758 return traits_type::not_eof(c);
1762 template <
typename C,
typename T>
1774 template <
typename C,
typename T>
1778 std::streamsize done = 0;
1781 if (std::streamsize nbuf = this->epptr() - this->pptr())
1783 nbuf = std::min(nbuf, n - done);
1784 traits_type::copy(this->pptr(), s + done, nbuf);
1797 template <
typename C,
typename T>
1801 const std::streamsize count = this->pptr() - this->pbase();
1804 const std::streamsize written = this->
write(this->wbuffer_, count);
1807 if (
const std::streamsize unwritten = count - written)
1808 traits_type::move(this->pbase(), this->pbase()+written, unwritten);
1809 this->pbump(-written);
1823 template <
typename C,
typename T>
1824 typename basic_pstreambuf<C,T>::int_type
1827 if (this->gptr() < this->egptr() ||
fill_buffer())
1828 return traits_type::to_int_type(*this->gptr());
1830 return traits_type::eof();
1841 template <
typename C,
typename T>
1842 typename basic_pstreambuf<C,T>::int_type
1845 if (this->gptr() != this->eback())
1848 if (!traits_type::eq_int_type(c, traits_type::eof()))
1849 *this->gptr() = traits_type::to_char_type(c);
1850 return traits_type::not_eof(c);
1853 return traits_type::eof();
1856 template <
typename C,
typename T>
1861 if (
sizeof(char_type) == 1)
1862 avail =
fill_buffer(
true) ? this->egptr() - this->gptr() : -1;
1866 if (::ioctl(
rpipe(), FIONREAD, &avail) == -1)
1869 avail /=
sizeof(char_type);
1872 return std::streamsize(avail);
1878 template <
typename C,
typename T>
1882 const std::streamsize pb1 = this->gptr() - this->eback();
1883 const std::streamsize pb2 = pbsz;
1884 const std::streamsize npb = std::min(pb1, pb2);
1886 char_type*
const rbuf =
rbuffer();
1889 traits_type::move(rbuf + pbsz - npb, this->gptr() - npb, npb);
1891 std::streamsize rc = -1;
1895 const int flags = ::fcntl(
rpipe(), F_GETFL);
1898 const bool blocking = !(flags & O_NONBLOCK);
1900 ::fcntl(
rpipe(), F_SETFL, flags | O_NONBLOCK);
1903 rc =
read(rbuf + pbsz, bufsz - pbsz);
1905 if (rc == -1 && error_ == EAGAIN)
1911 ::fcntl(
rpipe(), F_SETFL, flags);
1915 rc =
read(rbuf + pbsz, bufsz - pbsz);
1917 if (rc > 0 || (rc == 0 && non_blocking))
1919 this->setg( rbuf + pbsz - npb,
1926 this->setg(NULL, NULL, NULL);
1938 template <
typename C,
typename T>
1939 inline std::streamsize
1942 std::streamsize nwritten = 0;
1949 nwritten /=
sizeof(char_type);
1961 template <
typename C,
typename T>
1962 inline std::streamsize
1965 std::streamsize nread = 0;
1968 nread =
::read(
rpipe(), s, n *
sizeof(char_type));
1972 nread /=
sizeof(char_type);
1978 template <
typename C,
typename T>
1986 template <
typename C,
typename T>
1990 return rpipe_[rsrc_];
1994 template <
typename C,
typename T>
1998 return rpipe_[which];
2002 template <
typename C,
typename T>
2003 inline typename basic_pstreambuf<C,T>::char_type*
2006 return rbuffer_[rsrc_];
2023 template <
typename C,
typename T>
2026 : std::basic_ios<C,T>(NULL)
2030 this->std::basic_ios<C,T>::rdbuf(&
buf_);
2041 template <
typename C,
typename T>
2044 : std::basic_ios<C,T>(NULL)
2048 this->std::basic_ios<C,T>::rdbuf(&
buf_);
2061 template <
typename C,
typename T>
2066 : std::basic_ios<C,T>(NULL)
2070 this->std::basic_ios<C,T>::rdbuf(&
buf_);
2083 template <
typename C,
typename T>
2097 template <
typename C,
typename T>
2102 this->setstate(std::ios_base::failbit);
2114 template <
typename C,
typename T>
2121 this->setstate(std::ios_base::failbit);
2125 template <
typename C,
typename T>
2130 this->setstate(std::ios_base::failbit);
2137 template <
typename C,
typename T>
2145 template <
typename C,
typename T>
2146 inline const std::string&
2154 template <
typename C,
typename T>
2162 #if REDI_EVISCERATE_PSTREAMS 2195 template <
typename C,
typename T>
2199 in = out = err = NULL;
2200 std::size_t open_files = 0;
2203 if ((in = ::fdopen(wpipe(),
"w")))
2208 if (rpipe(rsrc_out) > -1)
2210 if ((out = ::fdopen(rpipe(rsrc_out),
"r")))
2215 if (rpipe(rsrc_err) > -1)
2217 if ((err = ::fdopen(rpipe(rsrc_err),
"r")))
2235 template <
typename C,
typename T>
2239 return buf_.fopen(fin, fout, ferr);
2242 #endif // REDI_EVISCERATE_PSTREAMS 2252 #endif // REDI_PSTREAM_H_SEEN void close_fd(pstreams::fd_type &fd)
Helper function to close a file descriptor.
Definition: pstream.h:1148
int_type overflow(int_type c)
Transfer characters to the pipe when character buffer overflows.
Definition: pstream.h:1751
std::streamsize write(const char_type *s, std::streamsize n)
Insert a sequence of characters into the pipe.
Definition: pstream.h:1940
void open(const std::string &cmd, pmode mode=pstdout|pstdin)
Start a process.
Definition: pstream.h:906
basic_opstream(const std::string &cmd, pmode mode=pstdin)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:529
pbase_type::argv_type argv_type
Type used to hold the arguments for a command.
Definition: pstream.h:823
fd_type fd_t
Definition: pstream.h:101
~basic_pstream()
Destructor.
Definition: pstream.h:725
fd_type & wpipe()
Return the file descriptor for the output pipe.
Definition: pstream.h:1980
Class template for Bidirectional PStreams.
Definition: pstream.h:636
char_type * rbuffer()
Return the active input buffer.
Definition: pstream.h:2004
Class template for stream buffer.
Definition: pstream.h:89
pbase_type::pmode pmode
Type used to specify how to connect to the process.
Definition: pstream.h:356
bool is_open() const
Report whether the stream buffer has been initialised.
Definition: pstream.h:1713
std::streamsize read(char_type *s, std::streamsize n)
Extract a sequence of characters from the pipe.
Definition: pstream.h:1963
basic_rpstream()
Default constructor, creates an uninitialised stream.
Definition: pstream.h:826
basic_pstream()
Default constructor, creates an uninitialised stream.
Definition: pstream.h:654
int error() const
Return the error number (errno) for the most recent failed operation.
Definition: pstream.h:1683
pbase_type::pmode pmode
Type used to specify how to connect to the process.
Definition: pstream.h:508
const std::string & command() const
Return the command used to initialise the stream.
Definition: pstream.h:2147
bool read_err(bool readerr=true)
Change active input source.
Definition: pstream.h:1728
virtual ~pstream_common()=0
Pure virtual destructor.
Definition: pstream.h:2085
void close_fd_array(pstreams::fd_type(&fds)[N])
Helper function to close an array of file descriptors.
Definition: pstream.h:1166
std::vector< std::string > argv_type
Type used to hold the arguments for a command.
Definition: pstream.h:70
pbase_type::argv_type argv_type
Type used to hold the arguments for a command.
Definition: pstream.h:359
pstream_common()
Default constructor.
Definition: pstream.h:2025
int_type underflow()
Transfer characters from the pipe when the character buffer is empty.
Definition: pstream.h:1825
void open(const std::string &cmd, pmode mode=pstdout|pstdin)
Start a process.
Definition: pstream.h:737
void open(const std::string &file, const argv_type &argv, pmode mode=pstdout|pstdin)
Start a process.
Definition: pstream.h:922
Class template for common base class.
Definition: pstream.h:265
basic_rpstream(const argv_type &argv, pmode mode=pstdout|pstdin)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:873
basic_ipstream(const argv_type &argv, pmode mode=pstdout)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:409
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:684
basic_opstream()
Default constructor, creates an uninitialised stream.
Definition: pstream.h:514
basic_pstreambuf< char > pstreambuf
Type definition for common template specialisation.
Definition: pstream.h:956
basic_ipstream(const std::string &cmd, pmode mode=pstdout)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:377
static const pmode pstderr
Read from stderr.
Definition: pstream.h:77
int status() const
Return the exit status of the process.
Definition: pstream.h:1673
int_type pbackfail(int_type c=traits_type::eof())
Make a character available to be returned by the next extraction.
Definition: pstream.h:1843
Common base class providing constants and typenames.
Definition: pstream.h:64
void open(const std::string &cmd, pmode mode=pstdout)
Start a process.
Definition: pstream.h:439
bool fill_buffer(bool non_blocking=false)
Definition: pstream.h:1880
static const pmode pstdout
Read from stdout.
Definition: pstream.h:76
int sync()
Write any buffered characters to the stream.
Definition: pstream.h:1764
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:856
basic_pstreambuf()
Default constructor.
Definition: pstream.h:1003
std::string command_
The command used to start the process.
Definition: pstream.h:320
bool exited()
Report whether the process has exited.
Definition: pstream.h:1660
bool is_open() const
Report whether the stream's buffer has been initialised.
Definition: pstream.h:2139
streambuf_type buf_
The stream buffer.
Definition: pstream.h:321
buf_read_src
Enumerated type to indicate whether stdout or stderr is to be read.
Definition: pstream.h:202
basic_pstream & out()
Set streambuf to read from process' stdout.
Definition: pstream.h:765
basic_pstream(const std::string &cmd, pmode mode=pstdout|pstdin)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:669
basic_pstreambuf * open(const std::string &cmd, pmode mode)
Initialise the stream buffer with cmd.
Definition: pstream.h:1101
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:392
Class template for Input PStreams.
Definition: pstream.h:336
pbase_type::argv_type argv_type
Type used to hold the arguments for a command.
Definition: pstream.h:651
std::streamsize xsputn(const char_type *s, std::streamsize n)
Insert multiple characters into the pipe.
Definition: pstream.h:1776
pid_t fork(pmode mode)
Initialise pipes and fork process.
Definition: pstream.h:1309
basic_ipstream & err()
Set streambuf to read from process' stderr.
Definition: pstream.h:478
basic_pstream & err()
Set streambuf to read from process' stderr.
Definition: pstream.h:776
basic_opstream(const argv_type &argv, pmode mode=pstdin)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:561
basic_rpstream< char > rpstream
Type definition for common template specialisation.
Definition: pstream.h:964
basic_ipstream & out()
Set streambuf to read from process' stdout.
Definition: pstream.h:467
pbase_type::argv_type argv_type
Type used to hold the arguments for a command.
Definition: pstream.h:511
All PStreams classes are declared in namespace redi.
int fd_type
Type used for file descriptors.
Definition: pstream.h:73
streambuf_type * rdbuf() const
Return a pointer to the stream buffer.
Definition: pstream.h:2156
~basic_pstreambuf()
Destructor.
Definition: pstream.h:1067
basic_pstream(const argv_type &argv, pmode mode=pstdout|pstdin)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:701
std::ios_base::openmode pmode
Type used to specify how to connect to the process.
Definition: pstream.h:67
Class template for Restricted PStreams.
Definition: pstream.h:806
basic_pstreambuf * killpg(int signal=SIGTERM)
Send a signal to the process' process group.
Definition: pstream.h:1629
basic_pstreambuf * close()
Close the stream buffer and wait for the process to exit.
Definition: pstream.h:1426
bool empty_buffer()
Writes buffered characters to the process' stdin pipe.
Definition: pstream.h:1799
void open(const std::string &cmd, pmode mode=pstdin)
Start a process.
Definition: pstream.h:597
~basic_ipstream()
Destructor.
Definition: pstream.h:426
pbase_type::pmode pmode
Type used to specify how to connect to the process.
Definition: pstream.h:820
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:981
basic_ipstream< char > ipstream
Type definition for common template specialisation.
Definition: pstream.h:958
int wait(bool nohang=false)
Wait for the child process to exit.
Definition: pstream.h:1551
void open(const std::string &file, const argv_type &argv, pmode mode=pstdout)
Start a process.
Definition: pstream.h:455
Class template for Output PStreams.
Definition: pstream.h:496
static const pmode newpg
Create a new process group for the child process.
Definition: pstream.h:80
fd_type & rpipe()
Return the file descriptor for the active input pipe.
Definition: pstream.h:1988
void do_open(const std::string &cmd, pmode mode)
Start a process.
Definition: pstream.h:2099
istream_type & err()
Obtain a reference to the istream that reads the process' stderr.
Definition: pstream.h:947
basic_ipstream()
Default constructor, creates an uninitialised stream.
Definition: pstream.h:362
~basic_rpstream()
Destructor.
Definition: pstream.h:894
void close()
Close the pipe.
Definition: pstream.h:2127
void peof()
Close the pipe connected to the process' stdin.
Definition: pstream.h:1694
basic_opstream< char > opstream
Type definition for common template specialisation.
Definition: pstream.h:960
pbase_type::pmode pmode
Type used to specify how to connect to the process.
Definition: pstream.h:648
void open(const std::string &file, const argv_type &argv, pmode mode=pstdin)
Start a process.
Definition: pstream.h:613
basic_pstream< char > pstream
Type definition for common template specialisation.
Definition: pstream.h:962
static const pmode pstdin
Write to stdin.
Definition: pstream.h:75
std::streamsize showmanyc()
Report how many characters can be read from active input without blocking.
Definition: pstream.h:1858
void open(const std::string &file, const argv_type &argv, pmode mode=pstdout|pstdin)
Start a process.
Definition: pstream.h:753
basic_rpstream(const std::string &cmd, pmode mode=pstdout|pstdin)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:841
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:544
basic_pstreambuf * kill(int signal=SIGTERM)
Send a signal to the process.
Definition: pstream.h:1594
istream_type & out()
Obtain a reference to the istream that reads the process' stdout.
Definition: pstream.h:935
~basic_opstream()
Destructor.
Definition: pstream.h:585