This commit is contained in:
Pierre Valarcher 2021-09-29 17:15:47 +02:00
parent 213fe4f110
commit bec44289fc

View File

@ -0,0 +1,36 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <string.h>
int main(int argc, char *argv[]) {
pid_t pid;
int indice = 0;
if (argc < 2) {
perror("argument pas bon");
exit (0);
}
/* Est ce qu'il y a un pipe AA */
for (int i = 0; i < argc; i++) {
if (strcmp("AA", argv[i]) == 0) {
argv[i] = NULL;
indice = i;
break;
}
}
if (indice == 0)
/* si il n'y a pas de pipe AA */
execvp(argv[1], &argv[1]);
else {
/* si il y a un pipe AA */
pid = fork();
if (pid == 0)
execvp(argv[indice+1], &argv[indice+1]);
else execvp(argv[1], &argv[1]);
}
return EXIT_SUCCESS;
}