1

Piping into pager (less) from C program

view story
linux-howto

https://bbs.archlinux.org – You want to play with pipe/fork:#include <stdlib.h> #include <stdio.h> #include <unistd.h> void work(void) { int i; for (i=0; i<512; i++) { printf("Line %d\n", i); } } int main(void) { int pfds[2]; pid_t pid; if (pipe(pfds) < 0) { perror("pipe failed"); return EXIT_FAILURE; } pid = fork(); if (pid < 0) { perror("fork failed"); return EXIT_FAILURE; } else if (pid == 0) { /* child */ close(pfds[0]); /* close unused read end */ /* set write end of pipe as stdout for this child process */ dup2(pfds[1], STDOUT_ (HowTos)