allow selecting stdout and stderr with inpipestream
[libi2ncommon] / src / pipestream.hxx
index d13f312..fe9e8c0 100644 (file)
@@ -55,8 +55,10 @@ struct ExecResult
 typedef struct ExecResult ExecResult;
 
 std::string capture_exec(const std::string& command, ExecResult &rescode);
-std::string capture_exec(const char *const *command, ExecResult &rescode);
-std::string capture_exec(const std::vector<std::string>& command, ExecResult &rescode);
+std::string capture_exec(const char *const *command, ExecResult &rescode,
+                         const bool out=true, const bool err=false);
+std::string capture_exec(const std::vector<std::string>& command, ExecResult &rescode,
+                         const bool out=true, const bool err=false);
 
 inline std::string capture_exec (const std::string &command)
 {
@@ -97,9 +99,12 @@ protected:
     int *exit_status;
 
 public:
-    inpipebuf(const std::string& command);
-    inpipebuf(const char *const *command);
-    inpipebuf(const std::vector<std::string> &command);
+    inpipebuf(const std::string& command,
+              const bool out, const bool err);
+    inpipebuf(const char *const *command,
+              const bool out, const bool err);
+    inpipebuf(const std::vector<std::string> &command,
+              const bool out, const bool err);
 
     ~inpipebuf();
 
@@ -109,7 +114,8 @@ protected:
     virtual int_type underflow();
 
 private:
-    FILE *init_without_shell (const char *const *argv) const;
+    FILE *init_without_shell (const char *const *argv,
+                              const bool out, const bool err) const;
 };
 
 /** @brief stream around inpipebuf -- see comment there */
@@ -119,15 +125,19 @@ protected:
     inpipebuf buf;
 
 public:
-    inpipestream(const std::string& command)
-            : std::istream(&buf), buf(command)
+    inpipestream(const std::string& command,
+                 const bool out=true, const bool err=false)
+            : std::istream(&buf), buf(command, out, err)
     {}
-    inpipestream(const char *const command[])
-            : std::istream(&buf), buf(command)
+
+    inpipestream(const char *const command[],
+                 const bool out=true, const bool err=false)
+            : std::istream(&buf), buf(command, out, err)
     {}
 
-    inpipestream(const std::vector<std::string> &command)
-            : std::istream(&buf), buf(command)
+    inpipestream(const std::vector<std::string> &command,
+                 const bool out=true, const bool err=false)
+            : std::istream(&buf), buf(command, out, err)
     {}
 
     void store_exit_status(bool *_status_set, int *_exit_status)