diff --git a/Assignment-05/starter/dshlib.c b/Assignment-05/starter/dshlib.c index d07fc55394700fb600f9a5b561b10dc77a774e9d..619876db007235f9ac8be7edcc5e8e5ed386f4e5 100644 --- a/Assignment-05/starter/dshlib.c +++ b/Assignment-05/starter/dshlib.c @@ -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); @@ -86,7 +86,7 @@ int execute_pipeline(command_list_t *cmd_list) { } cmd_buff_t *cmd = &cmd_list->commands[i]; - execvp(cmd->argv[0], cmd->argv); + execvp(cmd->argv[0], cmd->argv); perror("execvp"); exit(EXIT_FAILURE); } else { @@ -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;