Skip to content

Instantly share code, notes, and snippets.

@MrPeanutButta
Last active December 15, 2015 23:29
Show Gist options
  • Save MrPeanutButta/5340464 to your computer and use it in GitHub Desktop.
Save MrPeanutButta/5340464 to your computer and use it in GitHub Desktop.
pipe output to 'more' or 'less'
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