diff --git a/Exemples/04-Exec/exo2TDgr2.c b/Exemples/04-Exec/exo2TDgr2.c new file mode 100644 index 0000000..63bfe4d --- /dev/null +++ b/Exemples/04-Exec/exo2TDgr2.c @@ -0,0 +1,36 @@ +#include +#include +#include +#include +#include + +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; +} \ No newline at end of file