fix(executing): return code on unknown cmd was unchanged, is now set to 127

This commit is contained in:
Khaïs COLIN 2025-04-16 14:59:22 +02:00
parent 9a32220945
commit 18225f3356
2 changed files with 8 additions and 3 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/27 16:21:56 by khais #+# #+# */
/* Updated: 2025/04/15 15:33:50 by khais ### ########.fr */
/* Updated: 2025/04/16 14:59:11 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,10 +27,11 @@
#include "../../postprocess/expansion/expand_wildcard.h"
#include "simple_cmd_execute_debug.h"
static void command_not_found(t_simple_cmd *cmd)
static void command_not_found(t_simple_cmd *cmd, t_minishell *app)
{
ft_dprintf(STDERR_FILENO, "minishell: %s: command not found\n",
cmd->words->word->word);
app->last_return_value = 127;
}
static t_redirect *do_redirection(t_redirect *redirection)
@ -101,7 +102,7 @@ void simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app)
exe = get_cmdpath(cmd->words->word->word, app);
if (exe == NULL)
{
command_not_found(cmd);
command_not_found(cmd, app);
return ;
}
pid = fork();

View file

@ -195,11 +195,15 @@ EOF
when_run <<EOF "unknown commands"
qwertyuiop
echo \$?
poiuytrewq
echo \$?
EOF
expecting <<EOF
minishell: qwertyuiop: command not found
127
minishell: poiuytrewq: command not found
127
EOF
when_run <<EOF "pwd works"