il ne faut pas rouvrir le file descriptor, le man precise quil reste ouvert apres un exec, mais il etait seulement en read, pourtant il y a toujours une erreur, ce nest plus la meme

This commit is contained in:
hugogogo
2021-10-20 00:33:41 +02:00
parent f2c8898fcc
commit f8c23f85b4
2 changed files with 2 additions and 3 deletions

View File

@@ -30,8 +30,7 @@ void exec_cmd(char **envp, t_list *cmd_list)
{
if (cmd->fd_in != 0)
close(cmd->fd_in);
// if (cmd->fd_out != 1 && cmd->fd_redirect == 1)
if (cmd->fd_out != 1)
if (cmd->fd_out != 1 && cmd->fd_redirect == 1)
close(cmd->fd_out);
}
while ((wpid = wait(&status)) > 0);

View File

@@ -45,7 +45,7 @@ int handle_fd(char **input, int i, int fdin, t_cmd *cmd)
{
tmp[0] = '\0';
tmp = ft_strtrim(tmp + 2, " "); // +2 for "> "
cmd->fd_out = open(tmp, O_WRONLY | O_TRUNC);
cmd->fd_out = open(tmp, O_RDWR | O_TRUNC);
next_in = cmd->fd_out;
cmd->fd_redirect = cmd->fd_out;
}