2021-04-18 15:19:21 +02:00
|
|
|
#include "fastfetch.h"
|
|
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
|
2021-05-01 16:54:59 +02:00
|
|
|
void ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[])
|
2021-04-18 15:19:21 +02:00
|
|
|
{
|
|
|
|
|
int pipes[2];
|
|
|
|
|
|
|
|
|
|
if(pipe(pipes) == -1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
pid_t childPid = fork();
|
|
|
|
|
if(childPid == -1)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-03-17 16:52:19 +01:00
|
|
|
//Child
|
2021-04-18 15:19:21 +02:00
|
|
|
if(childPid == 0)
|
|
|
|
|
{
|
|
|
|
|
dup2(pipes[1], STDOUT_FILENO);
|
|
|
|
|
close(pipes[0]);
|
|
|
|
|
close(pipes[1]);
|
2021-05-01 21:27:46 +02:00
|
|
|
close(STDERR_FILENO);
|
2021-04-18 15:19:21 +02:00
|
|
|
execvp(argv[0], argv);
|
|
|
|
|
exit(901);
|
|
|
|
|
}
|
2022-03-17 16:52:19 +01:00
|
|
|
|
|
|
|
|
//Parent
|
|
|
|
|
close(pipes[1]);
|
|
|
|
|
waitpid(childPid, NULL, 0);
|
|
|
|
|
ffAppendFDContent(pipes[0], buffer);
|
|
|
|
|
close(pipes[0]);
|
2021-04-18 15:19:21 +02:00
|
|
|
}
|