|
@ -160,6 +160,7 @@ int check_pipe(char **args, char **pipe_arg_1, char **pipe_arg_2) |
|
|
} |
|
|
} |
|
|
pipe_arg_1[j++] = args[i++]; |
|
|
pipe_arg_1[j++] = args[i++]; |
|
|
} |
|
|
} |
|
|
|
|
|
pipe_arg_1[j] = NULL; |
|
|
|
|
|
|
|
|
j = 0; |
|
|
j = 0; |
|
|
i++; |
|
|
i++; |
|
@ -167,6 +168,7 @@ int check_pipe(char **args, char **pipe_arg_1, char **pipe_arg_2) |
|
|
{ |
|
|
{ |
|
|
pipe_arg_2[j++] = args[i++]; |
|
|
pipe_arg_2[j++] = args[i++]; |
|
|
} |
|
|
} |
|
|
|
|
|
pipe_arg_2[j] = NULL; |
|
|
return pipe_flag; |
|
|
return pipe_flag; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -245,19 +247,18 @@ int execute(char *cmdline, char **args) |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
int fds[2]; |
|
|
int fds[2]; |
|
|
|
|
|
pipe(fds); |
|
|
pid_t prog_1, prog_2; |
|
|
pid_t prog_1, prog_2; |
|
|
|
|
|
|
|
|
printf("%s %s %s %s %s %s\n", pipe_arg_1[0], pipe_arg_1[1], pipe_arg_1[3], pipe_arg_1[4], pipe_arg_1[5]); |
|
|
|
|
|
|
|
|
|
|
|
printf("%s %s %s %s %s %s\n", pipe_arg_2[0], pipe_arg_2[1], pipe_arg_2[3], pipe_arg_2[4], pipe_arg_2[5]); |
|
|
|
|
|
|
|
|
printf("%s %s %s %s", pipe_arg_1[0], pipe_arg_1[1], pipe_arg_1[2], pipe_arg_1[3]); |
|
|
|
|
|
|
|
|
if ((prog_1 = fork()) == 0) /* Child process 1 */ |
|
|
if ((prog_1 = fork()) == 0) /* Child process 1 */ |
|
|
{ |
|
|
{ |
|
|
dup2(fds[1], 1); |
|
|
|
|
|
dup2(fds[1], 2); |
|
|
|
|
|
|
|
|
close(1); |
|
|
|
|
|
dup(fds[1]); |
|
|
close(fds[0]); |
|
|
close(fds[0]); |
|
|
close(fds[1]); |
|
|
close(fds[1]); |
|
|
setpgid(0, 0); |
|
|
|
|
|
|
|
|
|
|
|
if (execvp(pipe_arg_1[0], pipe_arg_1) <= 0) |
|
|
if (execvp(pipe_arg_1[0], pipe_arg_1) <= 0) |
|
|
{ |
|
|
{ |
|
|
printf("%s: Command not found\n", pipe_arg_1[0]); |
|
|
printf("%s: Command not found\n", pipe_arg_1[0]); |
|
@ -267,10 +268,11 @@ int execute(char *cmdline, char **args) |
|
|
|
|
|
|
|
|
if ((prog_2 = fork()) == 0) /* Child process 1 */ |
|
|
if ((prog_2 = fork()) == 0) /* Child process 1 */ |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
dup2(fds[0], 0); |
|
|
dup2(fds[0], 0); |
|
|
close(fds[0]); |
|
|
close(fds[0]); |
|
|
close(fds[1]); |
|
|
close(fds[1]); |
|
|
setpgid(0, 0); |
|
|
|
|
|
|
|
|
|
|
|
if (execvp(pipe_arg_2[0], pipe_arg_2) <= 0) |
|
|
if (execvp(pipe_arg_2[0], pipe_arg_2) <= 0) |
|
|
{ |
|
|
{ |
|
|
printf("%s: Command not found\n", pipe_arg_2[0]); |
|
|
printf("%s: Command not found\n", pipe_arg_2[0]); |
|
@ -281,12 +283,11 @@ int execute(char *cmdline, char **args) |
|
|
close(fds[0]); |
|
|
close(fds[0]); |
|
|
close(fds[1]); |
|
|
close(fds[1]); |
|
|
|
|
|
|
|
|
wait(0); |
|
|
|
|
|
wait(0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
waitpid(prog_1, NULL, 0); |
|
|
|
|
|
waitpid(prog_2, NULL, 0); |
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
return 1; |
|
|
|
|
|
|
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int built_in(char **args) |
|
|
int built_in(char **args) |
|
|