diff --git a/minishell.c b/minishell.c index 471cfe0..a23e521 100644 --- a/minishell.c +++ b/minishell.c @@ -41,9 +41,9 @@ int caller(t_command *cmd) close(cmd->fd[1]); if (cmd->next) return (caller(cmd->next)); - waitpid(pid, &status, 0); if (cmd->fd[0]) close(cmd->fd[0]); + waitpid(pid, &status, 0); return (1); } diff --git a/parser.c b/parser.c index 7eeefb5..d64fe2a 100644 --- a/parser.c +++ b/parser.c @@ -12,18 +12,22 @@ #include "minishell.h" -void push_heredoc(char *str, int fd) +int push_heredoc(char *str) { char *line; + int pip[2]; - while(1) - { - line = readline(">"); - if (!ft_strncmp(line, str, ft_strlen(str) + 1)) - break; - ft_putstr_fd(line, fd); - write(fd, "\n", 1); - } + pipe(pip); + while(1) + { + line = readline(">"); + if (!ft_strncmp(line, str, ft_strlen(str) + 1)) + break; + ft_putstr_fd(line, pip[1]); + write(pip[1], "\n", 1); + } + close(pip[1]); + return (pip[0]); } size_t count_arguments(t_token *tok) @@ -64,8 +68,7 @@ void update_redir(t_command *cmd, t_token *tok) { if (cmd->fd[0]) close(cmd->fd[0]); - cmd->fd[0] = 0; - cmd->heredoc = tok->value; + cmd->fd[0] = push_heredoc(tok->value); } }