diff --git a/src/commands.c b/src/commands.c index 13e9c330aedcb9d3c1c0979a5b22fd7844516ada..b66155b677384793f9e41e9ffc0cdbb685d74baf 100644 --- a/src/commands.c +++ b/src/commands.c @@ -2,6 +2,7 @@ #include <stdlib.h> #include <string.h> #include <assert.h> +#include <unistd.h> #include "commands.h" #include "built_in.h" @@ -49,8 +50,25 @@ 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] == '/'){ + /* process creation */ + int _pid = fork(); + + if (_pid == 0) { + /* execv system call's 1st parameter : all path */ + /* If execv return '-1', ERROR. */ + //printf("_pid = 0 \n"); + if(execv(com->argv[0], com->argv) == -1){ + fprintf(stderr, "Execv Error\n"); + exit(0); + } + } + else if(_pid < 0) { + fprintf(stderr, "Fork Error\n"); + return -1; + } } else { - fprintf(stderr, "%s: command not found\n", com->argv[0]); + fprintf(stderr, "%s : command not found\n", com->argv[0]); return -1; } } diff --git a/src/signal_handlers.c b/src/signal_handlers.c index aab0ba26dfb6c2d799a5ae8c7a948f714ab8d4cc..ac5caae4516f81a0b60ca1cbe2fe2aab94cca4b4 100644 --- a/src/signal_handlers.c +++ b/src/signal_handlers.c @@ -4,11 +4,9 @@ void catch_sigint(int signalNo) { // Ctrl + C - signal(SIGINT, catch_sigint); } void catch_sigtstp(int signalNo) { // Ctrl + Z - signal(SIGTSTP, catch_sigtstp); }