Skip to content
Snippets Groups Projects
Commit 020ce659 authored by Joey Le's avatar Joey Le
Browse files

Hopefully execut pipeline works correctly now

parent 8a478ec5
No related branches found
No related tags found
No related merge requests found
......@@ -73,7 +73,7 @@ int execute_pipeline(command_list_t *cmd_list) {
return ERR_MEMORY;
}
if (pids[i] == 0) { // Child process
if (pids[i] == 0) {
if (prev_pipe_read != -1) {
dup2(prev_pipe_read, STDIN_FILENO);
close(prev_pipe_read);
......@@ -101,6 +101,20 @@ int execute_pipeline(command_list_t *cmd_list) {
}
}
if (prev_pipe_read != -1) {
char buffer[1024];
ssize_t bytes_read;
while ((bytes_read = read(prev_pipe_read, buffer, sizeof(buffer) - 1)) {
if (bytes_read < 0) {
perror("read");
break;
}
buffer[bytes_read] = '\0';
printf("%s", buffer);
}
close(prev_pipe_read);
}
for (int i = 0; i < num_commands; i++) {
waitpid(pids[i], NULL, 0);
}
......@@ -108,6 +122,7 @@ int execute_pipeline(command_list_t *cmd_list) {
return OK;
}
int parse_pipeline(char *cmd_line, command_list_t *clist) {
if (cmd_line == NULL || clist == NULL) {
return ERR_CMD_OR_ARGS_TOO_BIG;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment