Exemple #1
0
static void     exec(char **tab, char **env, const char *full_path)
{
  pid_t         pid;

  pid = fork();
  if (pid == 0)
  {
    reset_signals_state();
    if (full_path != NULL)
      xexecve(full_path, tab, env);
    else
      xexecve(tab[0], tab, env);
    exit(EXIT_FAILURE);
  }
  else if (pid > 0)
    wait(NULL);
  else
    print_errno(tab[0]);
}
Exemple #2
0
int	execute_last_command(t_tree *tree, t_shell *st_shell)
{
  int	statut;
  pid_t	pid;

  if (is_builtin(tree->args[0]))
    return (check_builtins(st_shell, tree));
  if ((pid = xfork()) == 0)
    {
      xdup2(tree->fd_in, 0);
      xdup2(tree->fd_out, 1);
      xexecve(tree->full_path, tree->args, st_shell->my_env);
    }
  else if (pid > 0)
    {
      if (waitpid(pid, &statut, 0) == -1)
	perror("Waitpid() :");
      else
	return (write_statut(statut));
    }
  return (FATAL_ERROR);
}