|  | @@ -8,9 +8,14 @@
 | 
	
		
			
				|  |  |  #include <stdio.h>
 | 
	
		
			
				|  |  |  #include <stdlib.h>
 | 
	
		
			
				|  |  |  #include <unistd.h>
 | 
	
		
			
				|  |  | +#include <sys/types.h>
 | 
	
		
			
				|  |  | +#include <wait.h>
 | 
	
		
			
				|  |  |  #include "error.h"
 | 
	
		
			
				|  |  |  #include "execute.h"
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +/* --- Extern --- */
 | 
	
		
			
				|  |  | +extern Error error;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  /* --- Fonctions publiques --- */
 | 
	
		
			
				|  |  |  boolean is_executable_file(const char * cmd) {
 | 
	
		
			
				|  |  |      int result;
 | 
	
	
		
			
				|  | @@ -19,4 +24,40 @@ boolean is_executable_file(const char * cmd) {
 | 
	
		
			
				|  |  |          return false;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      return true;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +int exec_shell(char* name, char** argv){
 | 
	
		
			
				|  |  | +    pid_t pid;  
 | 
	
		
			
				|  |  | +    int result;
 | 
	
		
			
				|  |  | +    //Fork pour l'exec
 | 
	
		
			
				|  |  | +    pid = fork();
 | 
	
		
			
				|  |  | +    if(pid == ERR){
 | 
	
		
			
				|  |  | +        addperror("Erreur lors du fork pour la commande execvp");
 | 
	
		
			
				|  |  | +        return EXIT_FAILURE;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    //Fils
 | 
	
		
			
				|  |  | +    else if(pid == 0){
 | 
	
		
			
				|  |  | +        //Reset sortie erreur
 | 
	
		
			
				|  |  | +        result = redirect_fd(STDERR, error.errfd);
 | 
	
		
			
				|  |  | +        if(result == ERR){
 | 
	
		
			
				|  |  | +            adderror("Impossible de redefinir la sortie d'erreur standard");
 | 
	
		
			
				|  |  | +            exit(EXIT_FAILURE);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //Execute commande
 | 
	
		
			
				|  |  | +        execvp(name, argv);
 | 
	
		
			
				|  |  | +        //Si on arrive ici alors erreur
 | 
	
		
			
				|  |  | +        addperror("Impossible d'executer la commande");
 | 
	
		
			
				|  |  | +        exit(EXIT_FAILURE);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    //Pere
 | 
	
		
			
				|  |  | +    wait(&result);
 | 
	
		
			
				|  |  | +    //Retourne retour fils
 | 
	
		
			
				|  |  | +    if(WIFEXITED(result)){
 | 
	
		
			
				|  |  | +        return WEXITSTATUS(result);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    return EXIT_FAILURE;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +int exec_file(char* name, char** argv){
 | 
	
		
			
				|  |  | +    return 1;
 | 
	
		
			
				|  |  |  }
 |