poject.c terminé
This commit is contained in:
@@ -67,11 +67,11 @@ int exec_cmd(char** args){
|
|||||||
// Child
|
// Child
|
||||||
else if (pid == 0){
|
else if (pid == 0){
|
||||||
|
|
||||||
if(strcmp(*args , "run") != 0) exit(-1);
|
if(strcmp(args[0] , "run") != 0) exit(-1);
|
||||||
else exit(execvp("run", args));
|
|
||||||
char child_buffer[2048];
|
if(execvp(args[1], args + 1) != 0) exit(-1);
|
||||||
fgets(child_buffer, 2047, stdout);
|
exit(0);
|
||||||
printf("%s\n", child_buffer);
|
|
||||||
//if(execvp(args[0], args) == -1) exit(-1);
|
//if(execvp(args[0], args) == -1) exit(-1);
|
||||||
//exit(0);
|
//exit(0);
|
||||||
}
|
}
|
||||||
@@ -84,8 +84,10 @@ int exec_cmd(char** args){
|
|||||||
|
|
||||||
if(waitpid(pid, &wstatus, 0) == -1) return -1;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +104,7 @@ int execution_loop(){
|
|||||||
char **args;
|
char **args;
|
||||||
while (1){ //boucle inf
|
while (1){ //boucle inf
|
||||||
|
|
||||||
puts("> "); //invitation à entrer une coooooooommmmmaaaaaaaannnnndde
|
fputs("> ", stdout); //invitation à entrer une coooooooommmmmaaaaaaaannnnndde
|
||||||
|
|
||||||
// on recupere le texte tapé grace a stdin
|
// on recupere le texte tapé grace a stdin
|
||||||
fgets(buffer, 2047, stdin);
|
fgets(buffer, 2047, stdin);
|
||||||
@@ -116,28 +118,31 @@ int execution_loop(){
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
while(args[index] != NULL) index ++;
|
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 (index > 0){ // si l'user rentre juste un ' ' ou rien
|
||||||
|
|
||||||
if (strcmp(args[0], "exit") == 0 ){
|
if (strcmp(args[0], "exit") == 0 ){
|
||||||
|
|
||||||
if (!args[1]) free(args);
|
if (args[1]) last_code = atoi(args[1]);
|
||||||
|
|
||||||
else{
|
else last_code = 0;
|
||||||
last_code = atoi(args[1]);
|
|
||||||
free(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
free(args);
|
||||||
return last_code;
|
return last_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//execution du run <commande> via le child
|
||||||
else if (strcmp(args[0], "run") == 0){
|
else if (strcmp(args[0], "run") == 0){
|
||||||
printf("test\n");
|
//printf("test\n");
|
||||||
last_code = exec_cmd(args);
|
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 {
|
else {
|
||||||
printf("Unknown command\n");
|
printf("Unknown command\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user