This commit is contained in:
Pierre Valarcher 2021-09-29 16:02:30 +02:00
parent 1981ce6285
commit 085b54b67a

View File

@ -0,0 +1,52 @@
#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 nb_pipe = 0;
int valDei;
char *argument[10];
if (argc <= 1) {
perror("pas le bon nb argument");
exit(0);
}
if (argc >= 10) {
perror("trop d'arguments");
exit(0);
}
for (int i = 0; i < argc; i++) {
argument[i] = argv[i+1];
if (strcmp(argument[i],"|") == 0) {
argument[i] = NULL;
valDei = i+1;
nb_pipe = 1;
}
}
argument[argc-1] = NULL;
pid = fork();
if (pid == 0) {
if (execvp(argv[1], argument) == -1)
{
perror("dans le exec");
exit (0);
}
if (nb_pipe > 0) {
if (execvp(argument[valDei], &argument[valDei]) == -1) {
perror("dans le exec");
exit (0);
}
}
} else {
wait(NULL);
}
return EXIT_SUCCESS;
}