diff --git a/include/execution.h b/include/execution.h index e3a9b14..a7365bd 100644 --- a/include/execution.h +++ b/include/execution.h @@ -6,7 +6,7 @@ /* By: mmoussou infile, STDIN_FILENO); + if (cmd->infile != STDIN_FILENO) + close(cmd->infile); + if (exec.status == -1) + exit(-1); + exec.status = dup2(cmd->outfile, STDOUT_FILENO); + if (cmd->outfile != STDOUT_FILENO) + close(cmd->outfile); + if (exec.pipe_fd[0] != -1) + close(exec.pipe_fd[0]); + if (exec.pipe_fd[0] != -1) + close(exec.pipe_fd[1]); + if (exec.status != -1) + exec_cmd(cmd->cmd, cmd->argv, env, env_t); + exit(-1); +} diff --git a/src/exec/exec_split_cmd.c b/src/exec/exec_split_cmd.c index b36ff99..7aab704 100644 --- a/src/exec/exec_split_cmd.c +++ b/src/exec/exec_split_cmd.c @@ -6,7 +6,7 @@ /* By: mmoussou infile, STDIN_FILENO); - if (cmd->infile != STDIN_FILENO) - close(cmd->infile); - if (exec.status == -1) - exit(-1); - exec.status = dup2(cmd->outfile, STDOUT_FILENO); - if (cmd->outfile != STDOUT_FILENO) - close(cmd->outfile); - if (exec.pipe_fd[0] != -1) - close(exec.pipe_fd[0]); - if (exec.pipe_fd[0] != -1) - close(exec.pipe_fd[1]); - if (exec.status != -1) - exec_cmd(cmd->cmd, cmd->argv, env, env_t); - exit(-1); -} - int exec_fork_cmd(t_cmd *cmd, char **env, t_env *env_t, int pipe_fd[2]) { t_exec exec;