void execution(char **tabb, t_env *chaine_env) { int j; char **path; char *str; char **env; char *value_path; j = 0; env = tab_env(chaine_env); if ((tabb[0][0] == '.' || tabb[0][0] == '/') && access(tabb[0], R_OK) == 0) execve(tabb[0], tabb, env); else if ((value_path = my_getenv("PATH", chaine_env)) != NULL) { path = my_str_to_wordtab(value_path, ':'); while (path[j] != NULL) { str = my_complete_str(path[j], tabb[0]); if (access(str, R_OK) == 0) execve(str, tabb, env); j++; xfree(str); } } printf("42sh: command not found : %s\n", tabb[0]); exit(-1); }
int redir_left(t_node *node, t_env *env) { int pfd[2]; char **cmd; char *pathcmd; int pid; if (pipe(pfd) == -1) return (-1); redir_left_rec(node->p_nx1, pfd, env); close(pfd[1]); cmd = my_str_to_wordtab(node->p_nx2->data); pid = fork(); if (pid == 0) { dup2(pfd[0], 0); pathcmd = my_check_access(cmd[0], my_get_path(env)); execve(pathcmd, cmd, tab_env(env)); return (-3); } else wait(&pid); my_free_tab(cmd); return (0); }