Browse Source

[enh] double redirection: do not go on certain part for last redirection.

Moul 3 years ago
parent
commit
ce4523d242
1 changed files with 9 additions and 4 deletions
  1. 9 4
      src/pipe_exec.c

+ 9 - 4
src/pipe_exec.c

@@ -12,8 +12,11 @@ void	launch_pipes(t_e *e, t_pipe *p, t_pipe_redir **t)
 	p->cmd_opt = (char***)malloc(sizeof(char**) * (p->nbr + 1));
 	while (++p->i <= p->pnbr)
 	{
-		p->cmd_opt[p->i] = cmd_splitting(e, t[p->i]->itxt, ' ');
-		remove_cotes(p->cmd_opt[p->i]);
+		if (t[p->i]->itxt != NULL)
+		{
+			p->cmd_opt[p->i] = cmd_splitting(e, t[p->i]->itxt, ' ');
+			remove_cotes(p->cmd_opt[p->i]);
+		}
 		open_redirections(e, p, t[p->i]);
 		if (ft_strcmp(t[p->i]->operator, "<<") != 0)
 			handle_multi_piping(e, p, t[p->i]);
@@ -48,7 +51,8 @@ void	handle_multi_piping(t_e *e, t_pipe *p, t_pipe_redir *t)
 {
 	int		ok;
 
-	ok = manage_cmd_1(e, p->cmd_opt[p->i]);
+	if (t->itxt != NULL)
+		ok = manage_cmd_1(e, p->cmd_opt[p->i]);
 	if (fork() == 0)
 	{
 		if (p->i < p->nbr)
@@ -76,7 +80,8 @@ void	inside_pipe(t_e *e, t_pipe *p, t_pipe_redir *t)
 {
 	if (ft_strstr(t->operator, ">") != NULL)
 		right_redirections(p, t);
-	manage_cmd_2(e, p->cmd_opt[p->i]);
+	if (t->itxt != NULL)
+		manage_cmd_2(e, p->cmd_opt[p->i]);
 	if (ft_strstr(t->operator, ">") != NULL)
 		close_redirections(e, p, t);
 }