This commit is contained in:
2024-04-25 19:20:46 +02:00
parent 1366c49e99
commit 36f7bfd64d
2 changed files with 16 additions and 26 deletions

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */
/* Updated: 2024/04/25 18:21:20 by tomoron ### ########.fr */
/* Updated: 2024/04/25 19:20:22 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -72,16 +72,17 @@ int exec(t_msh *msh, char **cmd_args, int i, int cmd_count)
void exec_command(t_msh *msh, int i, int cmd_count)
{
if(msh->in_fd == -1 || msh->out_fd == -1)
return ;
if(msh->out_fd != -1 || msh->in_fd != -1)
{
msh->fds[i] = ft_calloc(2, sizeof(int *));
if (!msh->fds[i])
ft_exit(msh, 1);
if (msh->tokens && !cmd_is_builtin(msh, msh->tokens->value))
get_cmd_path(msh);
if ((msh->tokens && msh->tokens->value) || is_parenthesis(msh->cmds))
exec(msh, get_cmd_args(msh), i, cmd_count);
}
g_return_code = 0;
msh->fds[i] = ft_calloc(2, sizeof(int *));
if (!msh->fds[i])
ft_exit(msh, 1);
if (msh->tokens && !cmd_is_builtin(msh, msh->tokens->value))
get_cmd_path(msh);
if ((msh->tokens && msh->tokens->value) || is_parenthesis(msh->cmds))
exec(msh, get_cmd_args(msh), i, cmd_count);
remove_command_from_msh(msh);
}
@ -134,7 +135,7 @@ void exec_commands(t_msh *msh)
if (!msh->pids || !msh->fds)
ft_exit(msh, 1);
i = -1;
while (++i < cmd_count)
while (++i < cmd_count && msh->in_fd >= 0 && msh->out_fd >= 0)
{
get_redirections(msh, msh->cmds);
exec_command(msh, i, cmd_count);