// // Written for Computer Networks and Systems lab classes // AUTHOR : Sergiusz Warga #include #include #include #include #include int main() { int pipefd[2]; if (pipe(pipefd) < 0) { fprintf(stderr, "Something went wrong!\n"); return -1; } pid_t pid; pid = fork(); if (pid == -1) { // If something went wrong. perror("Fork: "); exit(EXIT_FAILURE); } if (pid == 0) { // If this is a child process. dup2(pipefd[1], STDOUT_FILENO); execl("/usr/bin/cal", "cal", NULL); close(pipefd[1]); exit(EXIT_SUCCESS); } char buff[200] = {}; while (read(pipefd[0], &buff, sizeof(buff)) > 0) { printf("%s", buff); } int status; wait(&status); return 0; }