/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   executor_child.c                                   :+:    :+:            */
/*                                                     +:+                    */
/*   By: willem <willem@student.codam.nl>             +#+                     */
/*                                                   +#+                      */
/*   Created: 2025/02/12 21:25:10 by willem        #+#    #+#                 */
/*   Updated: 2025/02/26 16:09:44 by whaffman      ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include "minishell.h"

void	executor_child(t_minishell *msh, t_command *command)
{
	char	*path;

	if (command->fd_in != 0)
		dup2(command->fd_in, 0);
	if (command->fd_out != 1)
		dup2(command->fd_out, 1);
	executor_close_fds(command->n_fds);
	path = executor_absolute_path(msh, command->command);
	if (path == NULL)
	{
		ft_putstr_fd(RED BOLD, 2);
		ft_putstr_fd(command->command, 2);
		ft_putstr_fd(": " RESET "command not found\n", 2);
		return ;
	}
	execve(path, command->args, environment_get_arr(msh));
}
