From dcd623639fed9272795897a281d2cce5dfc26772 Mon Sep 17 00:00:00 2001 From: yosyo Date: Mon, 15 Jul 2024 21:06:03 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=E2=9C=8F=EF=B8=8F=E3=80=8D=20norm(exe?= =?UTF-8?q?c):=20normed=20project.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/execution.h | 5 +++- src/exec/exec_cmd.c | 62 +++++++++++++++++++++++++++++++++++++++ src/exec/exec_split_cmd.c | 50 +------------------------------ 3 files changed, 67 insertions(+), 50 deletions(-) create mode 100644 src/exec/exec_cmd.c 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;