| 130 | } |
| 131 | |
| 132 | int32_t ExecAndWaitForResponseRedirect(const char* path, char* const* args, int stdoutRedirect = -2, int stderrRedirect = -2) { |
| 133 | pid_t pid = fork(); |
| 134 | if (pid == 0) { |
| 135 | if (stdoutRedirect == -1) { |
| 136 | close(STDOUT_FILENO); |
| 137 | } else if (stdoutRedirect == -2) { |
| 138 | // Do nothing |
| 139 | } else { |
| 140 | if (stdoutRedirect != STDOUT_FILENO) { |
| 141 | close(STDOUT_FILENO); |
| 142 | } |
| 143 | dup2(stdoutRedirect, STDOUT_FILENO); |
| 144 | } |
| 145 | if (stderrRedirect == -1) { |
| 146 | close(STDERR_FILENO); |
| 147 | } else if (stderrRedirect == -2) { |
| 148 | // Do nothing |
| 149 | } else { |
| 150 | if (stderrRedirect != STDOUT_FILENO) { |
| 151 | close(STDERR_FILENO); |
| 152 | } |
| 153 | dup2(stderrRedirect, STDERR_FILENO); |
| 154 | } |
| 155 | execvp(path, args); |
| 156 | _exit(-1); |
| 157 | } else { |
| 158 | int32_t Status {}; |
| 159 | while (waitpid(pid, &Status, 0) == -1 && errno == EINTR) |
| 160 | ; |
| 161 | if (WIFEXITED(Status)) { |
| 162 | return (int8_t)WEXITSTATUS(Status); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | return -1; |
| 167 | } |
| 168 | |
| 169 | std::string ExecAndWaitForResponseText(const char* path, char* const* args) { |
| 170 | int fd[2]; |
no test coverage detected