mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
feat(redirection/group_cmd): handle redirections for group cmds
This commit is contained in:
parent
bd06d9f19c
commit
a9055b4c66
2 changed files with 38 additions and 2 deletions
|
|
@ -6,24 +6,33 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/04 19:50:42 by khais #+# #+# */
|
/* 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 "group_cmd_execute.h"
|
||||||
#include "../cmd/cmd_execute.h"
|
#include "../cmd/cmd_execute.h"
|
||||||
#include "../common/do_waitpid.h"
|
#include "../common/do_waitpid.h"
|
||||||
|
#include "../simple_cmd/handle_redirections.h"
|
||||||
|
#include "../simple_cmd/std_fds.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
void group_cmd_execute(t_group_cmd *cmd, t_minishell *app, bool should_exit)
|
void group_cmd_execute(t_group_cmd *cmd, t_minishell *app, bool should_exit)
|
||||||
{
|
{
|
||||||
int pid;
|
int pid;
|
||||||
|
t_std_fds fds;
|
||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
|
{
|
||||||
|
handle_redirections(cmd->redirects, app, &fds);
|
||||||
cmd_execute(cmd->cmd, app, true);
|
cmd_execute(cmd->cmd, app, true);
|
||||||
|
restore_std_fds(&fds);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
do_waitpid(app, pid);
|
do_waitpid(app, pid);
|
||||||
|
}
|
||||||
if (should_exit)
|
if (should_exit)
|
||||||
exit(app->last_return_value);
|
exit(app->last_return_value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
27
test.sh
27
test.sh
|
|
@ -1377,4 +1377,31 @@ expecting <<EOF
|
||||||
out*
|
out*
|
||||||
EOF
|
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
|
finalize
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue