mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
fix(exec): do now swallow prompt and io on incorrect command followed by redirection
This commit is contained in:
parent
65c1eb9d84
commit
d4da91b62b
2 changed files with 20 additions and 8 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/27 16:21:56 by khais #+# #+# */
|
/* Created: 2025/03/27 16:21:56 by khais #+# #+# */
|
||||||
/* Updated: 2025/04/28 14:42:13 by khais ### ########.fr */
|
/* Updated: 2025/04/28 15:57:23 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -81,15 +81,18 @@ static void exec_external_cmd(t_simple_cmd *cmd, t_minishell *app,
|
||||||
if (cmd->words == NULL)
|
if (cmd->words == NULL)
|
||||||
return (restore_std_fds(fds));
|
return (restore_std_fds(fds));
|
||||||
exe = get_cmdpath(cmd->words->word->word, app);
|
exe = get_cmdpath(cmd->words->word->word, app);
|
||||||
if (exe == NULL)
|
if (exe != NULL)
|
||||||
return (command_not_found(cmd, app));
|
{
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
execute_subprocess(exe, cmd, app, fds);
|
execute_subprocess(exe, cmd, app, fds);
|
||||||
restore_std_fds(fds);
|
|
||||||
free(exe);
|
free(exe);
|
||||||
do_waitpid(app, pid);
|
do_waitpid(app, pid);
|
||||||
}
|
}
|
||||||
|
restore_std_fds(fds);
|
||||||
|
if (exe == NULL)
|
||||||
|
command_not_found(cmd, app);
|
||||||
|
}
|
||||||
|
|
||||||
void simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app,
|
void simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app,
|
||||||
bool should_exit)
|
bool should_exit)
|
||||||
|
|
|
||||||
9
test.sh
9
test.sh
|
|
@ -1449,4 +1449,13 @@ hi
|
||||||
hello
|
hello
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
when_run <<EOF "incorrect command into redirection"
|
||||||
|
printff hello > bonjour
|
||||||
|
ls
|
||||||
|
EOF
|
||||||
|
expecting <<EOF
|
||||||
|
minishell: printff: command not found
|
||||||
|
bonjour
|
||||||
|
EOF
|
||||||
|
|
||||||
finalize
|
finalize
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue