|
|
@ -189,6 +189,8 @@ int execute(char *cmdline, char **args) |
|
|
|
bg = parseline(cmdline, args); |
|
|
|
redirect_flag = check_redirect(args, redirect_filename, redirect_args); |
|
|
|
|
|
|
|
printf("%s %s %s %s", redirect_args[0], redirect_args[1], redirect_args[2], redirect_filename); |
|
|
|
|
|
|
|
if (args[0] == NULL) |
|
|
|
{ |
|
|
|
return 1; |
|
|
@ -220,17 +222,25 @@ int execute(char *cmdline, char **args) |
|
|
|
/* Set the pid of the current process to the group number of the process group it belongs to. */ |
|
|
|
/* avoid being grouped with tsh */ |
|
|
|
setpgid(0, 0); |
|
|
|
if (execvp(args[0], args) <= 0) |
|
|
|
{ |
|
|
|
printf("%s: Command not found\n", args[0]); |
|
|
|
free(redirect_filename); |
|
|
|
free(redirect_args); |
|
|
|
exit(0); |
|
|
|
} |
|
|
|
|
|
|
|
if ((redirect_flag == 1) || (redirect_flag == 2)) |
|
|
|
{ |
|
|
|
|
|
|
|
if (execvp(redirect_args[0], redirect_args) <= 0) |
|
|
|
{ |
|
|
|
printf("%s: Command not found\n", args[0]); |
|
|
|
exit(0); |
|
|
|
} |
|
|
|
close(fd); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (execvp(args[0], args) <= 0) |
|
|
|
{ |
|
|
|
printf("%s: Command not found\n", args[0]); |
|
|
|
exit(0); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|