Delete commentaire
This commit is contained in:
parent
be031a442f
commit
cd750a160f
@ -7,14 +7,10 @@ void close_pipe(t_cmd *cmd)
|
||||
|
||||
i = 0;
|
||||
close(0);
|
||||
while (cmd->s_cmds[i])// && !cmd->s_cmds[i]->last)
|
||||
while (cmd->s_cmds[i])
|
||||
{
|
||||
//close(cmd->s_cmds[i]->last_pipe[0]);
|
||||
//close(cmd->s_cmds[i]->last_pipe[1]);
|
||||
close(cmd->s_cmds[i]->fd[0]);
|
||||
close(cmd->s_cmds[i]->fd[1]);
|
||||
//close(cmd->s_cmds[i]->pipe[0]);
|
||||
//close(cmd->s_cmds[i]->pipe[1]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@ -33,7 +29,6 @@ int wait_exit(t_cmd *cmd)
|
||||
{
|
||||
i = 0;
|
||||
exit_pid = wait(&status);
|
||||
//dprintf(2, "exit_pid= %d\n", exit_pid);
|
||||
while (exit_pid != -1 && cmd->s_cmds[i])
|
||||
{
|
||||
if (exit_pid == cmd->s_cmds[i]->child)
|
||||
@ -44,7 +39,6 @@ int wait_exit(t_cmd *cmd)
|
||||
i++;
|
||||
}
|
||||
}
|
||||
//dprintf(2, "return wait_exit\n");
|
||||
return (ret);
|
||||
}
|
||||
|
||||
@ -52,8 +46,6 @@ int wait_exit(t_cmd *cmd)
|
||||
|
||||
void exec_cmd(t_cmd *cmd, char **env, int *fdpipe)
|
||||
{
|
||||
// int ret;
|
||||
|
||||
cmd->current_s_cmd->child = fork();
|
||||
if (cmd->current_s_cmd->child == 0)
|
||||
{
|
||||
@ -71,36 +63,25 @@ void exec_cmd(t_cmd *cmd, char **env, int *fdpipe)
|
||||
|
||||
void execute(t_cmd *cmd, char **env)
|
||||
{
|
||||
//save in/out
|
||||
int fdpipe[2];
|
||||
//int ret;
|
||||
int fdout;
|
||||
int tmpin = dup(0);
|
||||
int tmpout= dup(1);
|
||||
int tmpin;
|
||||
int tmpout;
|
||||
int fdin;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
//close(0);
|
||||
//close(1);
|
||||
//if (cmd->current_s_cmd->infile)//set the initial input
|
||||
// fdin = open(cmd->current_s_cmd->infile, O_APPEND);
|
||||
//fdin = open(cmd->current_s_cmd->infile, O_RDONLY);
|
||||
//else if (cmd->infile)
|
||||
// fdin = open(cmd->infile, O_RDONLY);
|
||||
//else
|
||||
tmpin = dup(0);
|
||||
tmpout= dup(1);
|
||||
fdin=dup(tmpin);
|
||||
while(cmd->current_s_cmd)
|
||||
{
|
||||
if (i == cmd->nb_s_cmd - 1)
|
||||
{
|
||||
// Last simple command
|
||||
cmd->current_s_cmd->last = 1;
|
||||
if (cmd->current_s_cmd->outfile)
|
||||
fdout = open(cmd->current_s_cmd->outfile, O_RDWR | O_CREAT | O_APPEND, 0666);
|
||||
else if(cmd->outfile)
|
||||
fdout=open(cmd->outfile, O_RDWR | O_CREAT | O_TRUNC, 0666);
|
||||
else// Use default output
|
||||
else
|
||||
fdout=dup(tmpout);
|
||||
cmd->current_s_cmd->fd[0] = fdin;
|
||||
cmd->current_s_cmd->fd[1] = fdout;
|
||||
@ -110,32 +91,20 @@ void execute(t_cmd *cmd, char **env)
|
||||
{
|
||||
cmd->current_s_cmd->last = 0;
|
||||
pipe(fdpipe);
|
||||
//cmd->current_s_cmd->pipe[0] = fdpipe[0];
|
||||
//cmd->current_s_cmd->pipe[1] = fdpipe[1];
|
||||
cmd->current_s_cmd->fd[0] = fdin;//entree current
|
||||
cmd->current_s_cmd->fd[1] = fdpipe[1];//sortie current
|
||||
cmd->current_s_cmd->pipe[0] = fdpipe[0];//entree prochaine cmd
|
||||
cmd->current_s_cmd->pipe[1] = fdpipe[1];//sortie current
|
||||
cmd->s_cmds[i + 1]->last_pipe[0] = fdpipe[0];
|
||||
cmd->s_cmds[i + 1]->last_pipe[1] = fdpipe[1];
|
||||
//fdout=fdpipe[1];
|
||||
cmd->current_s_cmd->fd[0] = fdin;
|
||||
cmd->current_s_cmd->fd[1] = fdpipe[1];
|
||||
fdin=fdpipe[0];
|
||||
exec_cmd(cmd, env, fdpipe);
|
||||
close(cmd->current_s_cmd->fd[0]);
|
||||
}
|
||||
close(cmd->current_s_cmd->pipe[1]);
|
||||
close(fdpipe[1]);
|
||||
i++;
|
||||
cmd->current_s_cmd = cmd->s_cmds[i];
|
||||
} //while
|
||||
//restore in/out defaults
|
||||
}
|
||||
close_pipe(cmd);
|
||||
wait_exit(cmd);
|
||||
//wait(0);
|
||||
dup2(tmpin,0);
|
||||
dup2(tmpout,1);
|
||||
close(tmpin);
|
||||
close(tmpout);
|
||||
|
||||
// Wait for last command
|
||||
|
||||
} // execute
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user