mirror of
https://github.com/AGWA/git-crypt.git
synced 2025-12-26 12:50:39 -08:00
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:
27
util.cpp
27
util.cpp
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user