Add Coprocess class

It provides a convenient way to spawn a process and read from/write to
its stdin/stdout.
This commit is contained in:
Andrew Ayer
2015-05-24 18:54:11 -07:00
parent 3db6271492
commit 44f70e6b48
12 changed files with 992 additions and 305 deletions

View File

@@ -30,9 +30,36 @@
#include "git-crypt.hpp"
#include "util.hpp"
#include "coprocess.hpp"
#include <string>
#include <iostream>
int exec_command (const std::vector<std::string>& args)
{
Coprocess proc;
proc.spawn(args);
return proc.wait();
}
int exec_command (const std::vector<std::string>& args, std::ostream& output)
{
Coprocess proc;
std::istream* proc_stdout = proc.stdout_pipe();
proc.spawn(args);
output << proc_stdout->rdbuf();
return proc.wait();
}
int exec_command_with_input (const std::vector<std::string>& args, const char* p, size_t len)
{
Coprocess proc;
std::ostream* proc_stdin = proc.stdin_pipe();
proc.spawn(args);
proc_stdin->write(p, len);
proc.close_stdin();
return proc.wait();
}
std::string escape_shell_arg (const std::string& str)
{
std::string new_str;