From 66ea1328aa9b0ba51a717cdeeec9592aa61819e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Fri, 28 Mar 2025 16:57:00 +0100 Subject: [PATCH] simple_cmd executing: print error message on command not found --- src/executing/simple_cmd/simple_cmd_execute.c | 11 ++++++++++- test.sh | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/executing/simple_cmd/simple_cmd_execute.c b/src/executing/simple_cmd/simple_cmd_execute.c index 399ac6b..6a283e8 100644 --- a/src/executing/simple_cmd/simple_cmd_execute.c +++ b/src/executing/simple_cmd/simple_cmd_execute.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/27 16:21:56 by khais #+# #+# */ -/* Updated: 2025/03/27 18:32:18 by khais ### ########.fr */ +/* Updated: 2025/03/28 16:56:47 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,6 +32,12 @@ static char **argv_from_wordlist(t_wordlist *wordlist) return (out); } +static void command_not_found(t_simple_cmd *cmd) +{ + ft_dprintf(STDERR_FILENO, "minishell: %s: command not found\n", + cmd->words->word->word); +} + void simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app) { char *exe; @@ -41,7 +47,10 @@ void simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app) return ; exe = get_cmdpath(cmd->words->word->word, app); if (exe == NULL) + { + command_not_found(cmd); return ; + } pid = fork(); if (pid == 0) execve(exe, argv_from_wordlist(cmd->words), envp_from_env(app->env)); diff --git a/test.sh b/test.sh index d8ce306..2c2ea49 100755 --- a/test.sh +++ b/test.sh @@ -134,6 +134,15 @@ single file: t EOF +when_run <