Local works
This commit is contained in:
parent
8827ea5a42
commit
c9c5108254
@ -23,7 +23,8 @@ int execute_cmd(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int pipefd[2];
|
int pipefd[2];
|
||||||
if (output && pipe(pipefd) == -1) {
|
bool use_pipe = output && !interactive;
|
||||||
|
if (use_pipe && pipe(pipefd) == -1) {
|
||||||
perror("pipe");
|
perror("pipe");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -45,12 +46,12 @@ int execute_cmd(
|
|||||||
for (const auto& kv : env) {
|
for (const auto& kv : env) {
|
||||||
setenv(kv.first.c_str(), kv.second.c_str(), 1);
|
setenv(kv.first.c_str(), kv.second.c_str(), 1);
|
||||||
}
|
}
|
||||||
if (output) {
|
if (use_pipe) {
|
||||||
close(pipefd[0]);
|
close(pipefd[0]);
|
||||||
dup2(pipefd[1], STDOUT_FILENO);
|
dup2(pipefd[1], STDOUT_FILENO);
|
||||||
dup2(pipefd[1], STDERR_FILENO);
|
dup2(pipefd[1], STDERR_FILENO);
|
||||||
close(pipefd[1]);
|
close(pipefd[1]);
|
||||||
} else if (silent) {
|
} else if (silent && !interactive) {
|
||||||
int devnull = open("/dev/null", O_WRONLY);
|
int devnull = open("/dev/null", O_WRONLY);
|
||||||
dup2(devnull, STDOUT_FILENO);
|
dup2(devnull, STDOUT_FILENO);
|
||||||
dup2(devnull, STDERR_FILENO);
|
dup2(devnull, STDERR_FILENO);
|
||||||
@ -71,7 +72,7 @@ int execute_cmd(
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
} else {
|
} else {
|
||||||
// Parent process
|
// Parent process
|
||||||
if (output) {
|
if (use_pipe) {
|
||||||
close(pipefd[1]);
|
close(pipefd[1]);
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user