diff --git a/src/built_in.c b/src/built_in.c index d0a19fc1f3c41cc0b6610035f954cedfeb903f34..848b6f0a7594ab158606b6ac3f28d5ed4ef39bb4 100644 --- a/src/built_in.c +++ b/src/built_in.c @@ -3,6 +3,7 @@ #include <sys/types.h> #include <sys/stat.h> +#include <sys/wait.h> #include <unistd.h> #include <linux/limits.h> diff --git a/src/commands.c b/src/commands.c index 13e9c330aedcb9d3c1c0979a5b22fd7844516ada..cf22df40f90754dd216c174f61d1f83f90b13807 100644 --- a/src/commands.c +++ b/src/commands.c @@ -2,6 +2,15 @@ #include <stdlib.h> #include <string.h> #include <assert.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <sys/wait.h> +#include <errno.h> +#include <pthread.h> + + #include "commands.h" #include "built_in.h" @@ -49,6 +58,23 @@ int evaluate_command(int n_commands, struct single_command (*commands)[512]) return 0; } else if (strcmp(com->argv[0], "exit") == 0) { return 1; + } + else if(com->argv[0] > 0) { + pid_t pid; + pid = fork(); + + switch(pid) + { + case -1 : + printf("fail\n"); + case 0 : + execv(com->argv[0], com->argv); + printf("exec fail\n"); + default : + wait((int*)0); + printf("complete\n"); + exit(0); + } } else { fprintf(stderr, "%s: command not found\n", com->argv[0]); return -1;