simple_cmd executing: print error message on command not found

This commit is contained in:
Khaïs COLIN 2025-03-28 16:57:00 +01:00
parent a4c482e8f9
commit 66ea1328aa
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
2 changed files with 19 additions and 1 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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));

View file

@ -134,6 +134,15 @@ single file:
t
EOF
when_run <<EOF "unknown commands"
qwertyuiop
poiuytrewq
EOF
expecting <<EOF
minishell: qwertyuiop: command not found
minishell: poiuytrewq: command not found
EOF
when_run <<EOF "quoted parentheses are not operators"
echo unclosed '('
EOF