int			exec_pipe(t_tree *root)
{
	int		fd[2];
	pid_t	pid;
	int		i[2];

	pipe(fd);
	pid = fork();
	if (pid == 0)
	{
		close(fd[0]);
		dup2(fd[1], STDOUT_FILENO);
		i[1] = sh_interpret(root->left);
		close(fd[1]);
		exit(i[1] * 255);
	}
	else if (pid > 0)
	{
		close(fd[1]);
		dup2(fd[0], STDIN_FILENO);
		close(fd[0]);
		i[1] = sh_interpret(root->right);
		wait(&(i[0]));
		exec_free_root(root->left);
	}
	return (i[1]);
}
int			exec_or(t_tree *root)
{
	int		ret;

	if ((ret = sh_interpret(root->left)) == 0)
	{
		exec_free_root(root->right);
		return (ret);
	}
	else
	{
		sh_reset_std_fd();
		return (sh_interpret(root->right));
	}
}
int			exec_end(t_tree *root)
{
	char	*ret;
	int		i;

	i = sh_interpret(root->left);
	ret = ft_itoa(i);
	if ((sh_change_var_env("?", ret)) == -1)
		sh_add_var_env("?", ret);
	free(ret);
	sh_reset_std_fd();
	if (root->right != NULL)
		return (sh_interpret(root->right));
	else
		return (i);
}
예제 #4
0
int			exec_redout(t_tree *root)
{
	int		ret;
	int		fd[2];

	if (root->types == G_AND && root->cmd[1][0] == '-')
	{
		close(ft_atoi(root->cmd[0]));
		return (sh_interpret(root->right));
	}
	if ((fd[1] = exec_redout_g_and(root)) < 0)
		return (exec_free_root(root->right) + 1);
	fd[0] = ft_atoi(root->cmd[0]);
	if (fd[0] >= g_std_fd[0] && fd[0] <= g_std_fd[2])
		fd[0] = STDOUT_FILENO;
	if (root->types == AND_G)
		dup2(fd[1], STDERR_FILENO);
	dup2(fd[1], fd[0]);
	ret = sh_interpret(root->right);
	close(fd[1]);
	return (ret);
}