'Multi pipe in c cat | ls
I'm doing a little bash and for my pipe, I have everything work but the command cat | ls or cat | cat | ls that don't react as bash does. Here is my code.
The WNOHANG execute two fork.
Thank you!
void ft_pipe(t_list **token, t_list **cmp)
{
int fd[2];
int pid;
int fd_read;
char *exec_tube1;
int i;
fd_read = 0;
i = 1;
while ((*token) != NULL)
{
if (ft_get_path2(cmp, *token, &exec_tube1))
exit_failure("invalid cmd");
if (pipe(fd) == -1)
exit_failure("pipe() error");
pid = fork();
if (pid == -1)
exit_failure("fork() error");
else if (pid == 0)
{
dup2(fd_read, 0);
if ((*token)->next != NULL)
dup2(fd[1], 1);
ft_bultin(token);
g_err = execve(exec_tube1, (*token)->arg,
((t_myenv *)(*cmp)->env->content)->envp);
if (g_err == -1)
exit_failure((*token)->arg[0]);
ft_exit(g_err);
}
i++;
ft_close(fd[1], fd_read);
if (i % 2 == 0 && (*token)->next)
waitpid(0, NULL, WNOHANG);
else
ft_check_signal(pid);
fd_read = fd[0];
*token = (*token)->next;
}
ft_close(fd[1], fd_read);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
