From d9771f26a467fde143a2a5fad0ab94620432d8bf Mon Sep 17 00:00:00 2001 From: y-syo Date: Mon, 24 Jun 2024 14:06:31 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=8F=97=EF=B8=8F=E3=80=8D=20wip(e?= =?UTF-8?q?xec=5Fsingle=5Fcmd:command=5Fnot=5Ffound):=20correct=20command?= =?UTF-8?q?=20is=20not=20found=20msg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/exec/exec_split_cmd.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/exec/exec_split_cmd.c b/src/exec/exec_split_cmd.c index 3d28895..3e286b0 100644 --- a/src/exec/exec_split_cmd.c +++ b/src/exec/exec_split_cmd.c @@ -6,7 +6,7 @@ /* By: mmoussou cmd); status = switch_cmd_path(cmd, env_t); - if (status == -1 || access(cmd->cmd, X_OK)) + if (status == -1 || !input || access(cmd->cmd, X_OK)) + { + printf("minishell : command not found: %s\n", input); return (-1); + } fork_pid = fork(); - if (fork_pid == -1) - return (-1); if (!fork_pid) { status = dup2(cmd->infile, STDIN_FILENO); @@ -65,7 +68,7 @@ int exec_single_cmd(t_cmd *cmd, char **env, t_env *env_t, int pipe_fd[2]) execve(cmd->cmd, cmd->argv, env); exit(-1); } - return (0); + return (fork_pid); } void print_return_value(int return_code) @@ -124,9 +127,7 @@ int exec_split_cmd(t_list *list_cmd, t_env *env) close(((t_cmd *)(list_cmd->content))->outfile); if (((t_cmd *)(list_cmd->content))->infile != STDIN_FILENO) close(((t_cmd *)(list_cmd->content))->infile); - if (status) - printf("minishell : command not found: %s\n", ((t_cmd *)(list_cmd->content))->cmd); - else + if (!status) i++; list_cmd = list_cmd->next; } @@ -137,10 +138,7 @@ int exec_split_cmd(t_list *list_cmd, t_env *env) close(((t_cmd *)(list_cmd->content))->infile); ft_free("a", &env_array); if (status == -1) - { - printf("minishell : command not found: %s\n", ((t_cmd *)(list_cmd->content))->cmd); i--; - } if (i < 1) return (0); while (i)