1 #if !defined(_BTK_POPEN_HPP_)     2 #define _BTK_POPEN_HPP_    14     #define BTK_POPEN  ::_popen    15     #define BTK_PCLOSE ::_pclose    18     #define BTK_POPEN  ::popen    19     #define BTK_PCLOSE ::pclose    22 #include "../exception.hpp"    23 #include "../defs.hpp"    38             PStream(
const char *cmd,
const char *modes);
    53             void open(
const char *cmd,
const char *modes);
    54             void open(std::string_view cmd,std::string_view modes){
    55                 open(cmd.data(),modes.data());
    65             bool try_open(
const char *cmd,
const char *modes);
    66             bool try_open(std::string_view cmd,std::string_view modes){
    67                 return try_open(cmd.data(),modes.data());
    89             FILE *operator *() 
const noexcept{
   110             FILE *fptr = 
nullptr;
   113     inline PStream::PStream(
const char *cmd,
const char *modes){
   114         fptr = BTK_POPEN(cmd,modes);
   116             throwRuntimeError(strerror(errno));
   119     inline PStream::PStream(
PStream &&pstream){
   121         pstream.fptr = 
nullptr;
   123     inline PStream::~PStream(){
   135         return std::ferror(fptr);
   138         return std::feof(fptr);
   142         FILE *fp = BTK_POPEN(cmd,modes);
   144             throwRuntimeError(strerror(errno));
   150         FILE *fp = BTK_POPEN(cmd,modes);
   161         while(not std::feof(*stream)){
   162             ch = std::fgetc(*stream);
   175         std::fwrite(data.data(),
sizeof(char),data.length(),*stream);
   180         if(&pstream != 
this){
   183             pstream.fptr = 
nullptr;
   189 #endif // _BTK_POPEN_HPP_ bool bad()
Check the stream status. 
Definition: popen.hpp:134
This header include many useful containers. 
Definition: async.hpp:7
bool eof()
Check the stream at eof. 
Definition: popen.hpp:137
Pipe stream to or from a process. 
Definition: popen.hpp:29
friend PStream & operator<<(PStream &, std::string_view)
Write String to stream It w. 
Definition: popen.hpp:174
friend PStream & operator>>(PStream &, std::string &)
Read a line to string. 
Definition: popen.hpp:159
void close()
Close the stream. 
Definition: popen.hpp:127
PStream & operator=(PStream &&)
Assign from a lval stream. 
Definition: popen.hpp:179
void open(const char *cmd, const char *modes)
Open a new stream. 
Definition: popen.hpp:141
bool try_open(const char *cmd, const char *modes)
Trt open a new stream. 
Definition: popen.hpp:149