19 #ifndef REDI_PSTREAM_H_SEEN 20 #define REDI_PSTREAM_H_SEEN 32 #include <sys/types.h> 34 #include <sys/ioctl.h> 41 #if REDI_EVISCERATE_PSTREAMS 47 #define PSTREAMS_VERSION 0x0103 // 1.0.3 68 typedef std::ios_base::openmode
pmode;
76 static const pmode
pstdin = std::ios_base::out;
77 static const pmode
pstdout = std::ios_base::in;
78 static const pmode
pstderr = std::ios_base::app;
81 static const pmode
newpg = std::ios_base::trunc;
87 #if __cplusplus >= 201103L 89 using stringable = decltype((
void)std::string(std::declval<const T&>()));
94 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
96 :
public std::basic_streambuf<CharT, Traits>
120 #if __cplusplus >= 201103L 131 open(
const std::string& cmd,
pmode mode);
143 kill(
int signal = SIGTERM);
147 killpg(
int signal = SIGTERM);
155 read_err(
bool readerr =
true);
165 #if REDI_EVISCERATE_PSTREAMS 168 fopen(FILE*& in, FILE*& out, FILE*& err);
182 overflow(int_type c);
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);
247 fill_buffer(
bool non_blocking =
false);
257 #if __cplusplus >= 201103L 258 using basic_streambuf = std::basic_streambuf<char_type, traits_type>;
271 char_type* rbuffer_[2];
272 char_type* rbufstate_[3];
280 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
282 :
virtual public std::basic_ios<CharT, Traits>
299 pstream_common(
const std::string& file,
const argv_type& argv, pmode mode);
305 #if __cplusplus >= 201103L 307 : command_(std::move(rhs.command_))
308 , buf_(std::move(rhs.buf_))
316 command_ = std::move(rhs.command_);
317 buf_ = std::move(rhs.buf_);
325 command_.swap(rhs.command_);
332 do_open(
const std::string& cmd, pmode mode);
336 do_open(
const std::string& file,
const argv_type& argv, pmode mode);
356 #if REDI_EVISCERATE_PSTREAMS 359 fopen(FILE*& in, FILE*& out, FILE*& err);
378 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
380 :
public std::basic_istream<CharT, Traits>
387 using pbase_type::buf_;
406 : istream_type(NULL), pbase_type()
421 : istream_type(NULL), pbase_type(cmd, readable(mode))
436 const argv_type& argv,
438 : istream_type(NULL), pbase_type(file, argv, readable(mode))
453 : istream_type(NULL), pbase_type(argv.at(0), argv, readable(mode))
456 #if __cplusplus >= 201103L 457 template<
typename T,
typename =
stringable<T>>
460 : basic_ipstream(
argv_type(args.begin(), args.end()), mode)
463 basic_ipstream(basic_ipstream&& rhs)
464 : istream_type(std::move(rhs))
465 , pbase_type(std::move(rhs))
466 { istream_type::set_rdbuf(std::addressof(pbase_type::buf_)); }
469 operator=(basic_ipstream&& rhs)
471 istream_type::operator=(std::move(rhs));
472 pbase_type::operator=(std::move(rhs));
477 swap(basic_ipstream& rhs)
479 istream_type::swap(rhs);
480 pbase_type::swap(rhs);
504 this->do_open(cmd, readable(mode));
519 const argv_type& argv,
522 this->do_open(file, argv, readable(mode));
532 this->buf_.read_err(
false);
543 this->buf_.read_err(
true);
558 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
560 :
public std::basic_ostream<CharT, Traits>
567 using pbase_type::buf_;
578 : ostream_type(NULL), pbase_type()
593 : ostream_type(NULL), pbase_type(cmd, mode|
pstdin)
608 const argv_type& argv,
610 : ostream_type(NULL), pbase_type(file, argv, mode|
pstdin)
625 : ostream_type(NULL), pbase_type(argv.at(0), argv, mode|
pstdin)
628 #if __cplusplus >= 201103L 636 template<
typename T,
typename =
stringable<T>>
639 : basic_opstream(
argv_type(args.begin(), args.end()), mode)
642 basic_opstream(basic_opstream&& rhs)
643 : ostream_type(std::move(rhs))
644 , pbase_type(std::move(rhs))
645 { ostream_type::set_rdbuf(std::addressof(pbase_type::buf_)); }
648 operator=(basic_opstream&& rhs)
650 ostream_type::operator=(std::move(rhs));
651 pbase_type::operator=(std::move(rhs));
656 swap(basic_opstream& rhs)
658 ostream_type::swap(rhs);
659 pbase_type::swap(rhs);
682 this->do_open(cmd, mode|
pstdin);
697 const argv_type& argv,
700 this->do_open(file, argv, mode|
pstdin);
718 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
720 :
public std::basic_iostream<CharT, Traits>
727 using pbase_type::buf_;
738 : iostream_type(NULL), pbase_type()
753 : iostream_type(NULL), pbase_type(cmd, mode)
768 const argv_type& argv,
770 : iostream_type(NULL), pbase_type(file, argv, mode)
785 : iostream_type(NULL), pbase_type(argv.at(0), argv, mode)
788 #if __cplusplus >= 201103L 796 template<
typename T,
typename =
stringable<T>>
799 : basic_pstream(
argv_type(l.begin(), l.end()), mode)
802 basic_pstream(basic_pstream&& rhs)
803 : iostream_type(std::move(rhs))
804 , pbase_type(std::move(rhs))
805 { iostream_type::set_rdbuf(std::addressof(pbase_type::buf_)); }
808 operator=(basic_pstream&& rhs)
810 iostream_type::operator=(std::move(rhs));
811 pbase_type::operator=(std::move(rhs));
816 swap(basic_pstream& rhs)
818 iostream_type::swap(rhs);
819 pbase_type::swap(rhs);
842 this->do_open(cmd, mode);
857 const argv_type& argv,
860 this->do_open(file, argv, mode);
870 this->buf_.read_err(
false);
881 this->buf_.read_err(
true);
908 template <
typename CharT,
typename Traits = std::
char_traits<CharT> >
910 :
public std::basic_ostream<CharT, Traits>
911 ,
private std::basic_istream<CharT, Traits>
919 using pbase_type::buf_;
930 : ostream_type(NULL), istream_type(NULL), pbase_type()
945 : ostream_type(NULL) , istream_type(NULL) , pbase_type(cmd, mode)
960 const argv_type& argv,
962 : ostream_type(NULL), istream_type(NULL), pbase_type(file, argv, mode)
977 : ostream_type(NULL), istream_type(NULL)
978 , pbase_type(argv.at(0), argv, mode)
981 #if __cplusplus >= 201103L 989 template<
typename T,
typename =
stringable<T>>
992 : basic_rpstream(
argv_type(l.begin(), l.end()), mode)
998 basic_rpstream(basic_rpstream&& rhs)
999 : iostream_type(std::move(rhs))
1000 , pbase_type(std::move(rhs))
1001 { iostream_type::set_rdbuf(std::addressof(pbase_type::buf_)); }
1004 operator=(basic_rpstream&& rhs)
1006 iostream_type::operator=(std::move(rhs));
1007 pbase_type::operator=(std::move(rhs));
1012 swap(basic_rpstream& rhs)
1014 iostream_type::swap(rhs);
1015 pbase_type::swap(rhs);
1035 this->do_open(cmd, mode);
1050 const argv_type& argv,
1053 this->do_open(file, argv, mode);
1064 this->buf_.read_err(
false);
1076 this->buf_.read_err(
true);
1106 template <
typename C,
typename T>
1107 inline std::basic_ostream<C,T>&
1111 if (pstreambuf_type* p = dynamic_cast<pstreambuf_type*>(s.rdbuf()))
1128 template <
typename C,
typename T>
1151 template <
typename C,
typename T>
1176 template <
typename C,
typename T>
1179 const argv_type& argv,
1191 open(file, argv, mode);
1198 template <
typename C,
typename T>
1205 #if __cplusplus >= 201103L 1209 template <
typename C,
typename T>
1212 : basic_streambuf(static_cast<const basic_streambuf&>(rhs))
1215 ,
rpipe_{rhs.rpipe_[0], rhs.rpipe_[1]}
1217 ,
rbuffer_{rhs.rbuffer_[0], rhs.rbuffer_[1]}
1218 ,
rbufstate_{rhs.rbufstate_[0], rhs.rbufstate_[1], rhs.rbufstate_[2]}
1225 rhs.rpipe_[0] = rhs.rpipe_[1] = -1;
1226 rhs.wbuffer_ =
nullptr;
1227 rhs.rbuffer_[0] = rhs.rbuffer_[1] =
nullptr;
1228 rhs.rbufstate_[0] = rhs.rbufstate_[1] = rhs.rbufstate_[2] =
nullptr;
1232 rhs.setg(
nullptr,
nullptr,
nullptr);
1233 rhs.setp(
nullptr,
nullptr);
1236 template <
typename C,
typename T>
1241 basic_streambuf::operator=(static_cast<const basic_streambuf&>(rhs));
1246 template <
typename C,
typename T>
1250 basic_streambuf::swap(static_cast<basic_streambuf&>(rhs));
1290 template <
typename C,
typename T>
1294 const char * shell_path =
"/bin/sh";
1296 const std::string argv[] = {
"sh",
"-c", command };
1297 return this->
open(shell_path,
argv_type(argv, argv+3), mode);
1307 ::execl(shell_path,
"sh",
"-c", command.c_str(), (
char*)NULL);
1341 if (fd >= 0 && ::
close(fd) == 0)
1359 for (std::size_t i = 0; i < N; ++i)
1392 template <
typename C,
typename T>
1395 const argv_type& argv,
1406 fd_type ck_exec[] = { -1, -1 };
1407 if (-1 == ::pipe(ck_exec)
1408 || -1 == ::fcntl(ck_exec[RD], F_SETFD, FD_CLOEXEC)
1409 || -1 == ::fcntl(ck_exec[WR], F_SETFD, FD_CLOEXEC))
1421 char** arg_v =
new char*[argv.size()+1];
1422 for (std::size_t i = 0; i < argv.size(); ++i)
1424 const std::string& src = argv[i];
1425 char*& dest = arg_v[i];
1426 dest =
new char[src.size()+1];
1427 dest[ src.copy(dest, src.size()) ] =
'\0';
1429 arg_v[argv.size()] = NULL;
1431 ::execvp(file.c_str(), arg_v);
1438 while (::
write(ck_exec[WR], &error_,
sizeof(error_)) == -1
1498 template <
typename C,
typename T>
1507 fd_type fd[] = { -1, -1, -1, -1, -1, -1 };
1543 ::dup2(pin[RD], STDIN_FILENO);
1549 ::dup2(pout[WR], STDOUT_FILENO);
1555 ::dup2(perr[WR], STDERR_FILENO);
1559 #ifdef _POSIX_JOB_CONTROL 1615 template <
typename C,
typename T>
1619 const bool running =
is_open();
1635 }
while (
wait() == -1 &&
error() == EINTR);
1637 return running ? this : NULL;
1644 template <
typename C,
typename T>
1645 #if __cplusplus >= 201402L && __has_cpp_attribute(deprecated) 1648 __attribute__((deprecated))
1658 template <
typename C,
typename T>
1680 if (!(mode & pstdout))
1689 template <
typename C,
typename T>
1695 this->setp(NULL, NULL);
1702 this->setg(NULL, NULL, NULL);
1709 this->setg(NULL, NULL, NULL);
1715 template <
typename C,
typename T>
1721 char_type* tmpbufstate[] = {this->eback(), this->gptr(), this->egptr()};
1723 for (std::size_t i = 0; i < 3; ++i)
1746 template <
typename C,
typename T>
1750 int child_exited = -1;
1754 switch(::waitpid(
ppid_, &exit_status, nohang ? WNOHANG : 0))
1776 return child_exited;
1789 template <
typename C,
typename T>
1802 if (signal==SIGTERM || signal==SIGKILL)
1824 template <
typename C,
typename T>
1829 #ifdef _POSIX_JOB_CONTROL 1832 pid_t pgid = ::getpgid(
ppid_);
1835 else if (pgid == ::getpgrp())
1837 else if (::
killpg(pgid, signal))
1855 template <
typename C,
typename T>
1868 template <
typename C,
typename T>
1878 template <
typename C,
typename T>
1889 template <
typename C,
typename T>
1908 template <
typename C,
typename T>
1923 template <
typename C,
typename T>
1946 template <
typename C,
typename T>
1951 return traits_type::eof();
1952 else if (!traits_type::eq_int_type(c, traits_type::eof()))
1953 return this->sputc(c);
1955 return traits_type::not_eof(c);
1959 template <
typename C,
typename T>
1971 template <
typename C,
typename T>
1975 std::streamsize done = 0;
1978 if (std::streamsize nbuf = this->epptr() - this->pptr())
1980 nbuf = std::min(nbuf, n - done);
1981 traits_type::copy(this->pptr(), s + done, nbuf);
1994 template <
typename C,
typename T>
1998 const std::streamsize count = this->pptr() - this->pbase();
2001 const std::streamsize written = this->
write(this->
wbuffer_, count);
2004 if (
const std::streamsize unwritten = count - written)
2005 traits_type::move(this->pbase(), this->pbase()+written, unwritten);
2006 this->pbump(-written);
2020 template <
typename C,
typename T>
2024 if (this->gptr() < this->egptr() ||
fill_buffer())
2025 return traits_type::to_int_type(*this->gptr());
2027 return traits_type::eof();
2038 template <
typename C,
typename T>
2042 if (this->gptr() != this->eback())
2045 if (!traits_type::eq_int_type(c, traits_type::eof()))
2046 *this->gptr() = traits_type::to_char_type(c);
2047 return traits_type::not_eof(c);
2050 return traits_type::eof();
2053 template <
typename C,
typename T>
2058 if (
sizeof(char_type) == 1)
2059 avail =
fill_buffer(
true) ? this->egptr() - this->gptr() : -1;
2063 if (::ioctl(
rpipe(), FIONREAD, &avail) == -1)
2069 return std::streamsize(avail);
2075 template <
typename C,
typename T>
2079 const std::streamsize pb1 = this->gptr() - this->eback();
2080 const std::streamsize pb2 =
pbsz;
2081 const std::streamsize npb = std::min(pb1, pb2);
2083 char_type*
const rbuf =
rbuffer();
2086 traits_type::move(rbuf +
pbsz - npb, this->gptr() - npb, npb);
2088 std::streamsize rc = -1;
2092 const int flags = ::fcntl(
rpipe(), F_GETFL);
2095 const bool blocking = !(flags & O_NONBLOCK);
2097 ::fcntl(
rpipe(), F_SETFL, flags | O_NONBLOCK);
2102 if (rc == -1 &&
error_ == EAGAIN)
2108 ::fcntl(
rpipe(), F_SETFL, flags);
2114 if (rc > 0 || (rc == 0 && non_blocking))
2116 this->setg( rbuf +
pbsz - npb,
2123 this->setg(NULL, NULL, NULL);
2135 template <
typename C,
typename T>
2136 inline std::streamsize
2139 std::streamsize nwritten = 0;
2158 template <
typename C,
typename T>
2159 inline std::streamsize
2162 std::streamsize nread = 0;
2165 nread =
::read(
rpipe(), s, n *
sizeof(char_type));
2175 template <
typename C,
typename T>
2183 template <
typename C,
typename T>
2191 template <
typename C,
typename T>
2199 template <
typename C,
typename T>
2220 template <
typename C,
typename T>
2223 :
std::basic_ios<C,T>(NULL)
2227 this->std::basic_ios<C,T>::rdbuf(&
buf_);
2238 template <
typename C,
typename T>
2241 :
std::basic_ios<C,T>(NULL)
2245 this->std::basic_ios<C,T>::rdbuf(&
buf_);
2258 template <
typename C,
typename T>
2261 const argv_type& argv,
2263 :
std::basic_ios<C,T>(NULL)
2267 this->std::basic_ios<C,T>::rdbuf(&
buf_);
2280 template <
typename C,
typename T>
2294 template <
typename C,
typename T>
2299 this->setstate(std::ios_base::failbit);
2311 template <
typename C,
typename T>
2314 const argv_type& argv,
2318 this->setstate(std::ios_base::failbit);
2323 template <
typename C,
typename T>
2328 this->setstate(std::ios_base::failbit);
2336 template <
typename C,
typename T>
2344 template <
typename C,
typename T>
2345 inline const std::string&
2353 template <
typename C,
typename T>
2357 return const_cast<streambuf_type*
>(&
buf_);
2361 #if REDI_EVISCERATE_PSTREAMS 2394 template <
typename C,
typename T>
2398 in = out = err = NULL;
2399 std::size_t open_files = 0;
2402 if ((in = ::fdopen(wpipe(),
"w")))
2407 if (rpipe(rsrc_out) > -1)
2409 if ((out = ::fdopen(rpipe(rsrc_out),
"r")))
2414 if (rpipe(rsrc_err) > -1)
2416 if ((err = ::fdopen(rpipe(rsrc_err),
"r")))
2434 template <
typename C,
typename T>
2438 return buf_.fopen(fin, fout, ferr);
2441 #endif // REDI_EVISCERATE_PSTREAMS 2446 #endif // REDI_PSTREAM_H_SEEN void close_fd(pstreams::fd_type &fd)
Helper function to close a file descriptor.
Definition: pstream.h:1339
char_type * rbufstate_[3]
Definition: pstream.h:272
buf_read_src switch_read_buffer(buf_read_src)
Definition: pstream.h:1717
int_type overflow(int_type c)
Transfer characters to the pipe when character buffer overflows.
Definition: pstream.h:1948
std::streamsize write(const char_type *s, std::streamsize n)
Insert a sequence of characters into the pipe.
Definition: pstream.h:2137
void open(const std::string &cmd, pmode mode=pstdout|pstdin)
Start a process.
Definition: pstream.h:1033
basic_opstream(const std::string &cmd, pmode mode=pstdin)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:592
void create_buffers(pmode mode)
Definition: pstream.h:1660
pbase_type::argv_type argv_type
Type used to hold the arguments for a command.
Definition: pstream.h:926
fd_type fd_t
Definition: pstream.h:107
pmode readable(pmode mode)
Definition: pstream.h:390
~basic_pstream()
Destructor.
Definition: pstream.h:828
fd_type & wpipe()
Return the file descriptor for the output pipe.
Definition: pstream.h:2177
Class template for Bidirectional PStreams.
Definition: pstream.h:719
char_type * rbuffer()
Return the active input buffer.
Definition: pstream.h:2201
Class template for stream buffer.
Definition: pstream.h:95
pbase_type::pmode pmode
Type used to specify how to connect to the process.
Definition: pstream.h:399
bool is_open() const
Report whether the stream buffer has been initialised.
Definition: pstream.h:1910
std::streamsize read(char_type *s, std::streamsize n)
Extract a sequence of characters from the pipe.
Definition: pstream.h:2160
traits_type::int_type int_type
Definition: pstream.h:103
basic_rpstream()
Default constructor, creates an uninitialised stream.
Definition: pstream.h:929
basic_pstream()
Default constructor, creates an uninitialised stream.
Definition: pstream.h:737
int error() const
Return the error number (errno) for the most recent failed operation.
Definition: pstream.h:1880
std::basic_istream< CharT, Traits > istream_type
Definition: pstream.h:384
pbase_type::pmode pmode
Type used to specify how to connect to the process.
Definition: pstream.h:571
const std::string & command() const
Return the command used to initialise the stream.
Definition: pstream.h:2346
bool read_err(bool readerr=true)
Change active input source.
Definition: pstream.h:1925
pstream_common< CharT, Traits > pbase_type
Definition: pstream.h:917
fd_type rpipe_[2]
Definition: pstream.h:269
virtual ~pstream_common()=0
Pure virtual destructor.
Definition: pstream.h:2282
void close_fd_array(pstreams::fd_type(&fds)[N])
Helper function to close an array of file descriptors.
Definition: pstream.h:1357
traits_type::pos_type pos_type
Definition: pstream.h:105
pstream_common< CharT, Traits > pbase_type
Definition: pstream.h:385
std::vector< std::string > argv_type
Type used to hold the arguments for a command.
Definition: pstream.h:71
pbase_type::argv_type argv_type
Type used to hold the arguments for a command.
Definition: pstream.h:402
pstream_common()
Default constructor.
Definition: pstream.h:2222
int_type underflow()
Transfer characters from the pipe when the character buffer is empty.
Definition: pstream.h:2022
void open(const std::string &cmd, pmode mode=pstdout|pstdin)
Start a process.
Definition: pstream.h:840
void open(const std::string &file, const argv_type &argv, pmode mode=pstdout|pstdin)
Start a process.
Definition: pstream.h:1049
CharT char_type
Definition: pstream.h:101
Class template for common base class.
Definition: pstream.h:281
basic_rpstream(const argv_type &argv, pmode mode=pstdout|pstdin)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:976
basic_ipstream(const argv_type &argv, pmode mode=pstdout)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:452
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:767
basic_opstream()
Default constructor, creates an uninitialised stream.
Definition: pstream.h:577
basic_pstreambuf< char > pstreambuf
Type definition for common template specialisation.
Definition: pstream.h:1083
int status_
Definition: pstream.h:275
basic_ipstream(const std::string &cmd, pmode mode=pstdout)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:420
static const pmode pstderr
Read from stderr.
Definition: pstream.h:78
int status() const
Return the exit status of the process.
Definition: pstream.h:1870
int_type pbackfail(int_type c=traits_type::eof())
Make a character available to be returned by the next extraction.
Definition: pstream.h:2040
void destroy_buffers(pmode mode)
Definition: pstream.h:1691
Common base class providing constants and typenames.
Definition: pstream.h:65
void open(const std::string &cmd, pmode mode=pstdout)
Start a process.
Definition: pstream.h:502
bool fill_buffer(bool non_blocking=false)
Definition: pstream.h:2077
static const pmode pstdout
Read from stdout.
Definition: pstream.h:77
pstreams::pmode pmode
Definition: pstream.h:289
int sync()
Write any buffered characters to the stream.
Definition: pstream.h:1961
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:959
basic_pstreambuf()
Default constructor.
Definition: pstream.h:1130
pstream_common< CharT, Traits > pbase_type
Definition: pstream.h:565
std::string command_
The command used to start the process.
Definition: pstream.h:363
char_type * wbuffer_
Definition: pstream.h:270
bool exited()
Report whether the process has exited.
Definition: pstream.h:1857
bool is_open() const
Report whether the stream's buffer has been initialised.
Definition: pstream.h:2338
streambuf_type buf_
The stream buffer.
Definition: pstream.h:364
int close()
Definition: pstream.h:2325
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:868
basic_pstream(const std::string &cmd, pmode mode=pstdout|pstdin)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:752
basic_pstreambuf * open(const std::string &cmd, pmode mode)
Initialise the stream buffer with cmd.
Definition: pstream.h:1292
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:435
Class template for Input PStreams.
Definition: pstream.h:379
pstreams::argv_type argv_type
Definition: pstream.h:290
pbase_type::argv_type argv_type
Type used to hold the arguments for a command.
Definition: pstream.h:734
std::streamsize xsputn(const char_type *s, std::streamsize n)
Insert multiple characters into the pipe.
Definition: pstream.h:1973
pid_t fork(pmode mode)
Initialise pipes and fork process.
Definition: pstream.h:1500
std::basic_istream< CharT, Traits > istream_type
Definition: pstream.h:916
basic_ipstream & err()
Set streambuf to read from process' stderr.
Definition: pstream.h:541
basic_pstream & err()
Set streambuf to read from process' stderr.
Definition: pstream.h:879
std::basic_iostream< CharT, Traits > iostream_type
Definition: pstream.h:724
basic_opstream(const argv_type &argv, pmode mode=pstdin)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:624
basic_rpstream< char > rpstream
Type definition for common template specialisation.
Definition: pstream.h:1091
basic_ipstream & out()
Set streambuf to read from process' stdout.
Definition: pstream.h:530
pbase_type::argv_type argv_type
Type used to hold the arguments for a command.
Definition: pstream.h:574
All PStreams classes are declared in namespace redi.
basic_pstreambuf & operator=(const basic_pstreambuf &)
basic_pstreambuf< CharT, Traits > streambuf_type
Definition: pstream.h:286
int fd_type
Type used for file descriptors.
Definition: pstream.h:74
streambuf_type * rdbuf() const
Return a pointer to the stream buffer.
Definition: pstream.h:2355
~basic_pstreambuf()
Destructor.
Definition: pstream.h:1200
basic_pstream(const argv_type &argv, pmode mode=pstdout|pstdin)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:784
Traits traits_type
Definition: pstream.h:102
std::ios_base::openmode pmode
Type used to specify how to connect to the process.
Definition: pstream.h:68
Class template for Restricted PStreams.
Definition: pstream.h:909
basic_pstreambuf * killpg(int signal=SIGTERM)
Send a signal to the process' process group.
Definition: pstream.h:1826
basic_pstreambuf * close()
Close the stream buffer and wait for the process to exit.
Definition: pstream.h:1617
bool empty_buffer()
Writes buffered characters to the process' stdin pipe.
Definition: pstream.h:1996
void open(const std::string &cmd, pmode mode=pstdin)
Start a process.
Definition: pstream.h:680
std::basic_ostream< CharT, Traits > ostream_type
Definition: pstream.h:564
~basic_ipstream()
Destructor.
Definition: pstream.h:489
pbase_type::pmode pmode
Type used to specify how to connect to the process.
Definition: pstream.h:923
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:1108
std::basic_ios< CharT, Traits > ios_type
Definition: pstream.h:287
basic_ipstream< char > ipstream
Type definition for common template specialisation.
Definition: pstream.h:1085
fd_type wpipe_
Definition: pstream.h:268
int wait(bool nohang=false)
Wait for the child process to exit.
Definition: pstream.h:1748
pstream_common< CharT, Traits > pbase_type
Definition: pstream.h:725
void open(const std::string &file, const argv_type &argv, pmode mode=pstdout)
Start a process.
Definition: pstream.h:518
buf_read_src rsrc_
Index into rpipe_[] to indicate active source for read operations.
Definition: pstream.h:274
Class template for Output PStreams.
Definition: pstream.h:559
static const pmode newpg
Create a new process group for the child process.
Definition: pstream.h:81
std::basic_ostream< CharT, Traits > ostream_type
Definition: pstream.h:915
fd_type & rpipe()
Return the file descriptor for the active input pipe.
Definition: pstream.h:2185
void do_open(const std::string &cmd, pmode mode)
Start a process.
Definition: pstream.h:2296
istream_type & err()
Obtain a reference to the istream that reads the process' stderr.
Definition: pstream.h:1074
basic_ipstream()
Default constructor, creates an uninitialised stream.
Definition: pstream.h:405
~basic_rpstream()
Destructor.
Definition: pstream.h:1021
void peof()
Close the pipe connected to the process' stdin.
Definition: pstream.h:1891
basic_opstream< char > opstream
Type definition for common template specialisation.
Definition: pstream.h:1087
pbase_type::pmode pmode
Type used to specify how to connect to the process.
Definition: pstream.h:731
void open(const std::string &file, const argv_type &argv, pmode mode=pstdin)
Start a process.
Definition: pstream.h:696
pid_t ppid_
Definition: pstream.h:267
Definition: pstream.h:214
void init_rbuffers()
Definition: pstream.h:1651
basic_pstream< char > pstream
Type definition for common template specialisation.
Definition: pstream.h:1089
traits_type::off_type off_type
Definition: pstream.h:104
static const pmode pstdin
Write to stdin.
Definition: pstream.h:76
std::streamsize showmanyc()
Report how many characters can be read from active input without blocking.
Definition: pstream.h:2055
void open(const std::string &file, const argv_type &argv, pmode mode=pstdout|pstdin)
Start a process.
Definition: pstream.h:856
Definition: pstream.h:214
basic_rpstream(const std::string &cmd, pmode mode=pstdout|pstdin)
Constructor that initialises the stream by starting a process.
Definition: pstream.h:944
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:607
basic_pstreambuf * kill(int signal=SIGTERM)
Send a signal to the process.
Definition: pstream.h:1791
istream_type & out()
Obtain a reference to the istream that reads the process' stdout.
Definition: pstream.h:1062
char_type * rbuffer_[2]
Definition: pstream.h:271
~basic_opstream()
Destructor.
Definition: pstream.h:668
int error_
Definition: pstream.h:276