New exec_command() that takes command as array instead of string

This abstracts away the details of argument quoting, which differs
between Unix and Windows.

Also replace all uses of the system() library call with exec_command().
Although system() exists on Windows, it executes the command via cmd.exe,
which has ridiculous escaping rules.
This commit is contained in:
Andrew Ayer
2014-06-10 21:21:38 -07:00
parent 0774ed018c
commit 6e43b2a1cd
5 changed files with 200 additions and 92 deletions

View File

@@ -36,6 +36,7 @@
#include <iosfwd>
#include <stdint.h>
#include <fstream>
#include <vector>
struct System_error {
std::string action;
@@ -58,8 +59,9 @@ public:
void mkdir_parent (const std::string& path); // Create parent directories of path, __but not path itself__
std::string our_exe_path ();
int exec_command (const char* command, std::ostream& output);
int exec_command_with_input (const char* command, const char* p, size_t len);
int exec_command (const std::vector<std::string>&);
int exec_command (const std::vector<std::string>&, std::ostream& output);
int exec_command_with_input (const std::vector<std::string>&, const char* p, size_t len);
bool successful_exit (int status);
std::string escape_shell_arg (const std::string&);
uint32_t load_be32 (const unsigned char*);