diff --git a/AnimalProcessing/Fundamentals/exec.c b/AnimalProcessing/Fundamentals/exec.c index f370bf5..c4b3d48 100644 --- a/AnimalProcessing/Fundamentals/exec.c +++ b/AnimalProcessing/Fundamentals/exec.c @@ -42,4 +42,5 @@ printf("%d\n", r1); int r2 = execute_me("wrong", argv); printf("%d\n", r2); -}*/ +} +*/ diff --git a/AnimalProcessing/Fundamentals/pipe.c b/AnimalProcessing/Fundamentals/pipe.c index 8d5662e..866127f 100644 --- a/AnimalProcessing/Fundamentals/pipe.c +++ b/AnimalProcessing/Fundamentals/pipe.c @@ -44,7 +44,7 @@ void piped(){ char buffer[2048]; read(fd[0], buffer, sizeof(buffer)); - printf("My child sends me : %s\n", buffer); + printf("My child sends me : %s", buffer); close(fd[0]); wait(NULL); diff --git a/AnimalProcessing/Fundamentals/wait.c b/AnimalProcessing/Fundamentals/wait.c index 8e72937..b735f25 100644 --- a/AnimalProcessing/Fundamentals/wait.c +++ b/AnimalProcessing/Fundamentals/wait.c @@ -14,7 +14,7 @@ int fibo (int n){ } int wait_child(int x){ - if(x < 0) return -1; + if(x < 0) return 1; int wstatus; pid_t pid = fork(); diff --git a/AnimalProcessing/Proficiencies/dup.c b/AnimalProcessing/Proficiencies/dup.c index a695ab5..0f08f81 100644 --- a/AnimalProcessing/Proficiencies/dup.c +++ b/AnimalProcessing/Proficiencies/dup.c @@ -25,19 +25,29 @@ int duper(char **argv, char *output){ int wstatus; pid_t pid = fork(); - if(pid < 0) return 1; + if(pid < 0) { + + printf("Something went wrong in duper.\n"); + return 1; + } //Child else if (pid == 0){ // ouverture en mode write FILE *file = fopen(output, "w"); - if(!file) exit(-1); - + if(!file) { + printf("Something went wrong in duper.\n"); + exit(-1); + } int fno = fileno(file); - if(dup2(fno, STDOUT_FILENO) == -1) exit(-1); - + if(dup2(fno, STDOUT_FILENO) == -1){ + + printf("Something went wrong in duper.\n"); + exit(-1); + } + fclose(file); execvp(argv[0],argv); diff --git a/AnimalProcessing/Proficiencies/project.c b/AnimalProcessing/Proficiencies/project.c index 9135f6b..f34ceb3 100644 --- a/AnimalProcessing/Proficiencies/project.c +++ b/AnimalProcessing/Proficiencies/project.c @@ -65,17 +65,21 @@ int exec_cmd(char** args){ int wstatus; pid_t pid = fork(); - if (pid < 0) exit(-1); + if (pid < 0){ + free(args); + exit(-1); + } // Child else if (pid == 0){ - if(strcmp(args[0] , "run") != 0) exit(-1); - - if(execvp(args[1], args + 1) != 0) exit(-1); - exit(0); - - //if(execvp(args[0], args) == -1) exit(-1); + //if(strcmp(args[0] , "run") != 0) exit(-1); + + //on execute la commande et on return son code de fin + exit(execvp(args[1], args + 1)); + + //if(execvp(args[1], args + 1) != 0) exit(-1); //exit(0); + } //Uncle... You're again ! Oh it's not my uncle it's my daddy !