pipe sur redirection ne marche toujours pas
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/08 02:35:52 by lperrey #+# #+# */
|
||||
/* Updated: 2021/10/19 23:59:00 by hulamy ### ########.fr */
|
||||
/* Updated: 2021/10/20 09:11:41 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -25,6 +25,8 @@ typedef struct s_cmd
|
||||
char **argv;
|
||||
pid_t pid;
|
||||
void *builtin;
|
||||
int pipe_in;
|
||||
int pipe_out;
|
||||
int fd_redirect;
|
||||
int fd_in;
|
||||
int fd_out;
|
||||
|
||||
37
srcs/main.c
37
srcs/main.c
@@ -1,6 +1,27 @@
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void close_fd(t_cmd *cmd, pid_t pid)
|
||||
{
|
||||
if (cmd->fd_in != 0)
|
||||
close(cmd->fd_in);
|
||||
if (pid == 0)
|
||||
{
|
||||
if (cmd->pipe_out != 1)
|
||||
{
|
||||
close(cmd->pipe_in);
|
||||
close(cmd->pipe_out);
|
||||
}
|
||||
if (cmd->fd_out != 1)
|
||||
close(cmd->fd_out);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cmd->fd_out != 1 && cmd->fd_redirect == 1)
|
||||
close(cmd->fd_out);
|
||||
}
|
||||
}
|
||||
|
||||
void exec_cmd(char **envp, t_list *cmd_list)
|
||||
{
|
||||
t_cmd *cmd;
|
||||
@@ -15,23 +36,19 @@ void exec_cmd(char **envp, t_list *cmd_list)
|
||||
if (pid == 0)
|
||||
{
|
||||
if (cmd->fd_in != 0)
|
||||
{
|
||||
dup2(cmd->fd_in, STDIN_FILENO);
|
||||
close(cmd->fd_in);
|
||||
}
|
||||
if (cmd->fd_out != 1)
|
||||
{
|
||||
dup2(cmd->fd_out, STDOUT_FILENO);
|
||||
close(cmd->fd_out);
|
||||
}
|
||||
close_fd(cmd, pid);
|
||||
execve(cmd->argv[0], cmd->argv, envp);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cmd->fd_in != 0)
|
||||
close(cmd->fd_in);
|
||||
if (cmd->fd_out != 1 && cmd->fd_redirect == 1)
|
||||
close(cmd->fd_out);
|
||||
close_fd(cmd, pid);
|
||||
// if (cmd->fd_in != 0)
|
||||
// close(cmd->fd_in);
|
||||
// if (cmd->fd_out != 1 && cmd->fd_redirect == 1)
|
||||
// close(cmd->fd_out);
|
||||
}
|
||||
while ((wpid = wait(&status)) > 0);
|
||||
cmd_list = cmd_list->next;
|
||||
|
||||
@@ -32,6 +32,8 @@ int handle_fd(char **input, int i, int fdin, t_cmd *cmd)
|
||||
cmd->fd_in = fdin;
|
||||
cmd->fd_out = 1;
|
||||
cmd->fd_redirect = 1;
|
||||
cmd->pipe_in = 0;
|
||||
cmd->pipe_out = 1;
|
||||
next_in = 0;
|
||||
if (input[i + 1])
|
||||
{
|
||||
@@ -39,6 +41,8 @@ int handle_fd(char **input, int i, int fdin, t_cmd *cmd)
|
||||
pipe(pipes_fd);
|
||||
cmd->fd_out = pipes_fd[1];
|
||||
next_in = pipes_fd[0];
|
||||
cmd->pipe_in = pipes_fd[0];
|
||||
cmd->pipe_out = pipes_fd[1];
|
||||
}
|
||||
tmp = ft_strchr(input[i], '>');
|
||||
if (tmp)
|
||||
|
||||
Reference in New Issue
Block a user