Find the answer to your Linux question:
Results 1 to 4 of 4
does anybody know how to call the more pager within a progam. i wanna send the contents of a file to more within the program....
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2004
    Location
    Somwhere in India
    Posts
    11

    to call more pager within a c program


    does anybody know how to call the more pager within a progam. i wanna send the contents of a file to more within the program.

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    The easiest way is probably with popen. Something like this should do:
    Code:
    #include <stdio.h>
    
    int main&#40;int argc, char **argv&#41;
    &#123;
        FILE *morepipe;
        
        ... /* your code */
        morepipe = popen&#40;"more", "w"&#41;;
        ... /* write some data to morepipe, using any of the standard stdio calls, like fprintf, fputs, etc. */
        pclose&#40;morepipe&#41;;
        ... /* more of your code */
    &#125;

  3. #3
    Just Joined!
    Join Date
    Nov 2004
    Location
    Somwhere in India
    Posts
    11
    thanx dude. i'll try it.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Please note, though, that to be really compliant, you should just make it call "more", but actually check the value of the PAGER environment variable, like this:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main&#40;int argc, char **argv&#41;
    &#123;
        FILE *morepipe;
        char *morecmd;
       
        ... /* your code */
        if&#40;&#40;morecmd = getenv&#40;"PAGER"&#41;&#41; == NULL&#41;
            morecmd = "more";
        morepipe = popen&#40;morecmd, "w"&#41;;
        ... /* write some data to morepipe, using any of the standard stdio calls, like fprintf, fputs, etc. */
        pclose&#40;morepipe&#41;;
        ... /* more of your code */
    &#125;
    That way, the user can set PAGER to his/her favorite pager, such as less, cat or whatever the user prefers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •