Last active
December 15, 2015 23:29
-
-
Save MrPeanutButta/5340464 to your computer and use it in GitHub Desktop.
pipe output to 'more' or 'less'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int more(const char *buffer) { | |
pid_t pid(fork()); | |
int status(0); | |
if (!pid) { | |
FILE *output{}; | |
output = popen("more", "w"); | |
if (!output) { | |
fprintf(stderr, | |
"incorrect parameters or too many files.\n"); | |
return EXIT_FAILURE; | |
} | |
fprintf(output, "%s", buffer); | |
if (pclose(output) != 0) { | |
fprintf(stderr, | |
"Could not run more or other error.\n"); | |
} | |
exit(EXIT_SUCCESS); | |
}else waitpid(pid, &status, WUNTRACED | WCONTINUED); | |
return status; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment