feat(redirection/group_cmd): handle redirections for group cmds

This commit is contained in:
Khaïs COLIN 2025-04-25 18:12:58 +02:00
parent bd06d9f19c
commit a9055b4c66
2 changed files with 38 additions and 2 deletions

View file

@ -6,24 +6,33 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/04 19:50:42 by khais #+# #+# */
/* Updated: 2025/04/28 12:29:34 by khais ### ########.fr */
/* Updated: 2025/04/28 12:56:52 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "group_cmd_execute.h"
#include "../cmd/cmd_execute.h"
#include "../common/do_waitpid.h"
#include "../simple_cmd/handle_redirections.h"
#include "../simple_cmd/std_fds.h"
#include <unistd.h>
void group_cmd_execute(t_group_cmd *cmd, t_minishell *app, bool should_exit)
{
int pid;
int pid;
t_std_fds fds;
pid = fork();
if (pid == 0)
{
handle_redirections(cmd->redirects, app, &fds);
cmd_execute(cmd->cmd, app, true);
restore_std_fds(&fds);
}
else
{
do_waitpid(app, pid);
}
if (should_exit)
exit(app->last_return_value);
}

27
test.sh
View file

@ -1377,4 +1377,31 @@ expecting <<EOF
out*
EOF
when_run <<EOF "subshell combination with and"
((echo hello)&&echo hi)
EOF
expecting <<EOF
hello
hi
EOF
when_run <<EOF "nested subshell combination with and"
(echo hello&&((echo hi)))
EOF
expecting <<EOF
hello
hi
EOF
when_run <<EOF "subshell redirection with and"
(echo hello && echo hi) > outfile
ls
cat outfile
EOF
expecting <<EOF
outfile
hello
hi
EOF
finalize