ft_system.c 1.2 KB

123456789101112131415161718192021222324252627282930
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* ft_system.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@student.42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2017/12/20 11:11:15 by bchanot #+# #+# */
  9. /* Updated: 2018/10/14 03:28:18 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include <libft.h>
  13. #include <unistd.h>
  14. #include <sys/wait.h>
  15. void ft_system(char *src)
  16. {
  17. pid_t pid;
  18. char **tab;
  19. tab = ft_strsplit(src, ' ');
  20. pid = fork();
  21. if (pid < 0)
  22. ft_putendl("Fail to fork.");
  23. if (pid == 0)
  24. execve(tab[0], tab, 0);
  25. waitpid(pid, 0, 0);
  26. ft_memdel2((void ***)&tab);
  27. }