poject.c terminé

This commit is contained in:
2026-04-15 22:20:54 +02:00
parent 87f49dd1e4
commit 13347a4236
+21 -16
View File
@@ -67,11 +67,11 @@ int exec_cmd(char** args){
// Child
else if (pid == 0){
if(strcmp(*args , "run") != 0) exit(-1);
else exit(execvp("run", args));
char child_buffer[2048];
fgets(child_buffer, 2047, stdout);
printf("%s\n", child_buffer);
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);
//exit(0);
}
@@ -84,8 +84,10 @@ int exec_cmd(char** args){
if(waitpid(pid, &wstatus, 0) == -1) return -1;
if( WIFEXITED(wstatus)) return WEXITSTATUS(wstatus);
}
if( WIFEXITED(wstatus)){
if(WEXITSTATUS(wstatus) == 255) return 1;
else return WEXITSTATUS(wstatus);
}}
return 0;
}
@@ -102,7 +104,7 @@ int execution_loop(){
char **args;
while (1){ //boucle inf
puts("> "); //invitation à entrer une coooooooommmmmaaaaaaaannnnndde
fputs("> ", stdout); //invitation à entrer une coooooooommmmmaaaaaaaannnnndde
// on recupere le texte tapé grace a stdin
fgets(buffer, 2047, stdin);
@@ -116,28 +118,31 @@ int execution_loop(){
int index = 0;
while(args[index] != NULL) index ++;
printf("nbr args : %i\n", index);
// printf("nbr args : %i\n", index);
if (index > 0){ // si l'user rentre juste un ' ' ou rien
if (strcmp(args[0], "exit") == 0 ){
if (!args[1]) free(args);
if (args[1]) last_code = atoi(args[1]);
else last_code = 0;
else{
last_code = atoi(args[1]);
free(args);
}
return last_code;
}
//execution du run <commande> via le child
else if (strcmp(args[0], "run") == 0){
printf("test\n");
//printf("test\n");
last_code = exec_cmd(args);
}
else if (strcmp(args[0], "?") == 0) printf("%i\n", last_code);
//interrogation du last_code
else if (strcmp(args[0], "?") == 0){
printf("%i\n", last_code);
}
else {
printf("Unknown command\n");