Ejemplo n.º 1
0
void	first_pipe_traitement(char *buffer, char **env,
			      t_traite *tr, int pipefd[2])
{
  int	tst;
  int	directory;
  int	error;

  error = pipe(pipefd);
  if (error == -1)
    exit(EXIT_FAILURE);
  if ((tr->pid = fork()) == -1)
    exit(EXIT_FAILURE);
  if (tr->pid == 0)
    {
      tr->buff = epure_str(buffer);
      tr->tab = strtab(tr->buff);
      tr->path = find_path(env, tr->path);
      directory = current_directory(tr->tab);
      if (directory == 2)
	tr->exec = test(tr->path, tr->tab[0]);
      close(pipefd[0]);
      dup2(pipefd[1], 1);
      execve(tr->exec, tr->tab, env);
      exit(0);
    }
  waitpid(tr->pid, &tst, 0);
}
Ejemplo n.º 2
0
void	second_pipe_traitement(char *buffer, char **env,
			       t_traite *tr, int pipefd[2])
{
  int	tst;
  int	directory;

  if ((tr->pid = fork()) == -1)
    exit(EXIT_FAILURE);
  if (tr->pid == 0)
    {
      buffer = tr->tmp;
      buffer = cut_buff_pipe(buffer);
      tr->buff = epure_str(buffer);
      tr->tab = strtab(tr->buff);
      tr->path = find_path(env, tr->path);
      directory = current_directory(tr->tab);
      if (directory == 2)
	tr->exec = test(tr->path, tr->tab[0]);
      close(pipefd[1]);
      dup2(pipefd[0], 0);
      execve(tr->exec, tr->tab, env);
      exit(0);
    }
  close(pipefd[1]);
  close(pipefd[0]);
  wait(&tr->statut);
  if (WIFSIGNALED(tr->statut))
    my_putstr("Segmentation fault\n");
}
Ejemplo n.º 3
0
void		mysh()
{
  char          *buff;
  char		**tab_com;
  int		i;

  if ((buff = malloc(sizeof(char) * 8200)) == NULL)
    return;
  my_printf("&>");
  buff = r_com(buff);
  buff = epure_str(buff);

  my_printf("Commande : %s$\n", buff);

  tab_com = cut_com(buff);

  i = 0;
  while (tab_com[i])
    {
      my_printf("commande[%d] : %s\n", i, tab_com[i]);
      i++;
    }

}