src/process.cpp

changeset 18
fd7a7785c963
parent 4
82680ce258d6
equal deleted inserted replaced
17:bb4e34e77974 18:fd7a7785c963
39 void process::chdir(std::string path) { 39 void process::chdir(std::string path) {
40 m_dir = std::move(path); 40 m_dir = std::move(path);
41 } 41 }
42 42
43 int process::exec(std::vector<std::string> args, bool capture) { 43 int process::exec(std::vector<std::string> args, bool capture) {
44 if (args.size() > 14) {
45 fputs("Too many arguments to sub-process.\n", stderr);
46 return -1;
47 }
44 m_output.clear(); 48 m_output.clear();
45 49
46 // fd-pair for the pipe 50 // fd-pair for the pipe
47 int pipefd[2]; 51 int pipefd[2];
48 52
59 exit(EXIT_FAILURE); 63 exit(EXIT_FAILURE);
60 } 64 }
61 close(pipefd[0]); 65 close(pipefd[0]);
62 66
63 // create the execv argument list 67 // create the execv argument list
64 char *argv[args.size() + 2] = {}; 68 char *argv[16];
65 auto slash = m_path.find_last_of('/'); 69 auto slash = m_path.find_last_of('/');
66 if (slash == std::string::npos) { 70 if (slash == std::string::npos) {
67 argv[0] = m_path.data(); 71 argv[0] = m_path.data();
68 } else { 72 } else {
69 argv[0] = m_path.data() + slash + 1; 73 argv[0] = m_path.data() + slash + 1;

mercurial