diff --git a/srcs/exec_bonus.c b/srcs/exec_bonus.c index 3861b88..8f53371 100755 --- a/srcs/exec_bonus.c +++ b/srcs/exec_bonus.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */ -/* Updated: 2024/04/13 13:28:48 by babonnet ### ########.fr */ +/* Updated: 2024/04/13 16:22:58 by babonnet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -68,16 +68,16 @@ void exec_command_bonus(t_msh *msh, char *cmd_str) int exec(t_msh *msh, char **cmd_args, int i, int cmd_count) { pid_t pid; - int fds[2]; if (i != cmd_count - 1) { printf("pipe\n"); - if (pipe(fds) == -1) + if (pipe(msh->fds[i]) == -1) { perror("minishell: pipe"); ft_exit(msh, 1); } + ft_printf_fd(2, "msh->fds[%d][0]: %d, msh->fds[%d][1]: %d\n", i, msh->fds[i][0], i, msh->fds[i][1]); } pid = fork(); if (pid == -1) @@ -160,6 +160,8 @@ void exec_commands(t_msh *msh) i = 0; while (i < cmd_count) { + if (i != 0) + get_redirections(msh, msh->cmds); exec_command(msh, i, cmd_count); free(msh->fds[i]); i++; diff --git a/srcs/input_redirections.c b/srcs/input_redirections.c index a89fa3f..7b79faa 100755 --- a/srcs/input_redirections.c +++ b/srcs/input_redirections.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:15:27 by marde-vr #+# #+# */ -/* Updated: 2024/04/13 13:42:07 by babonnet ### ########.fr */ +/* Updated: 2024/04/13 15:58:27 by babonnet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,13 +16,15 @@ void redirect_input(t_msh *msh, int i) { if (msh->in_type != PIPE) { + ft_printf_fd(2, "redirecting input\n"); if (dup2(msh->in_fd, 0) < 0) ft_exit(msh, 1); close(msh->in_fd); } else { - ft_printf_fd(2, "%d: 0 -> %d\n", i, msh->fds[i - 1][0]); + ft_printf_fd(2, "redirecting pipe input\n"); + ft_printf_fd(2, "input of cmd %d: 0 -> %d\n", i, msh->fds[i - 1][0]); if (dup2(msh->fds[i - 1][0], 0) < 0) ft_exit(msh, 1); } diff --git a/srcs/output_redirections.c b/srcs/output_redirections.c index 39ad793..6b88955 100755 --- a/srcs/output_redirections.c +++ b/srcs/output_redirections.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 19:10:52 by marde-vr #+# #+# */ -/* Updated: 2024/04/13 13:42:29 by babonnet ### ########.fr */ +/* Updated: 2024/04/13 21:25:23 by babonnet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,12 +16,14 @@ void redirect_output(t_msh *msh, int i) { if (msh->out_type != PIPE) { + ft_printf_fd(2, "redirecting output\n"); if (dup2(msh->out_fd, 1) < 0) ft_exit(msh, 1); } else { - ft_printf_fd(2, "%d: 1 -> %d\n", i, msh->fds[i - 1][1]); + ft_printf_fd(0, "redirecting pipe output\n"); + ft_printf_fd(0, "output of cmd %d: 1 -> %d\n", i, msh->fds[i - 1][1]); if (dup2(msh->fds[i][1], 1) < 0) ft_exit(msh, 1); } diff --git a/srcs/pipe.c b/srcs/pipe.c index 45d86bc..32494b4 100755 --- a/srcs/pipe.c +++ b/srcs/pipe.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */ -/* Updated: 2024/04/13 13:39:31 by babonnet ### ########.fr */ +/* Updated: 2024/04/13 15:39:50 by babonnet ### ########.fr */ /* */ /* ************************************************************************** */