add pipestream ctor overload for vectors of string
[libi2ncommon] / src / pipestream.cpp
index ebcc6c2..cd9347a 100644 (file)
@@ -100,6 +100,11 @@ std::string capture_exec (const std::string &command, ExecResult &res)
 std::string capture_exec (const char *const *command, ExecResult &res)
 { return capture_exec<const char *const *>(command, res); }
 
+std::string capture_exec (const std::vector<std::string> &command, ExecResult &res)
+{
+    return capture_exec<const std::vector<std::string> &>(command, res);
+}
+
 #define PIPE_CTOR_FAIL(where) \
     do { \
         throw EXCEPTION (pipestream_error, \
@@ -197,6 +202,25 @@ inpipebuf::inpipebuf(const char *const *command)
     setg (&buffer, &buffer, &buffer);
 }
 
+inpipebuf::inpipebuf(const std::vector<std::string> &command)
+    : pipe (NULL) /* brr: shadowing global ident */
+    , status_set (NULL)
+    , exit_status (NULL)
+{
+    if (command.empty ()) {
+        PIPE_CTOR_FAIL("command");
+    }
+
+    const boost::shared_array <char *> argv = mk_argv (command);
+    if (!argv) {
+        PIPE_CTOR_FAIL("malloc");
+    }
+
+    this->pipe = this->init_without_shell (argv.get ());
+
+    setg (&buffer, &buffer, &buffer);
+}
+
 inpipebuf::inpipebuf(const std::string& command)
 {
     status_set = NULL;