popen/system()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HugoFromBOSS
    New Member
    • Sep 2007
    • 38

    popen/system()

    Hello,

    I have beeen googling for hours and havent found the answer I am looking for so I have come to experts. I hope you can help!

    FILE * snapshot;
    char mystring [100];

    snapshot = popen("screen -x svr00001", "r");
    pclose(snapshot );
    if (snapshot == NULL) {
    perror ("Not running");
    } else {
    fgets (mystring , 100 , snapshot);
    puts (mystring);
    }

    However, this "streams" the data that the "screen" command is running how do I get it to "print" out the last line being executed by the program?

    Thanks in advance!
  • Savage
    Recognized Expert Top Contributor
    • Feb 2007
    • 1759

    #2
    Originally posted by HugoFromBOSS
    Hello,

    I have beeen googling for hours and havent found the answer I am looking for so I have come to experts. I hope you can help!

    FILE * snapshot;
    char mystring [100];

    snapshot = popen("screen -x svr00001", "r");
    pclose(snapshot );
    if (snapshot == NULL) {
    perror ("Not running");
    } else {
    fgets (mystring , 100 , snapshot);
    puts (mystring);
    }

    However, this "streams" the data that the "screen" command is running how do I get it to "print" out the last line being executed by the program?

    Thanks in advance!
    Why do you close the stream immediately after opening it?

    Comment

    • HugoFromBOSS
      New Member
      • Sep 2007
      • 38

      #3
      To try and get it to only get a bit of data rather than streaming the execution of "screen"

      Comment

      • HugoFromBOSS
        New Member
        • Sep 2007
        • 38

        #4
        I just want to be able to return part of the screen command in a varialbe and not the whole screen execution.

        Comment

        • HugoFromBOSS
          New Member
          • Sep 2007
          • 38

          #5
          *bump* is there any way of doing this?

          Comment

          • rcronk
            New Member
            • Jan 2008
            • 6

            #6
            I don't know if it's valid to perform operations on something that has been closed. Have you tried closing it after you are done with it? If so, what happened?

            Comment

            • HugoFromBOSS
              New Member
              • Sep 2007
              • 38

              #7
              There is no diffrence its the same result.

              Comment

              • HugoFromBOSS
                New Member
                • Sep 2007
                • 38

                #8
                Is there another way of getting the information of a program running on "screen" on C.

                I want to be able to get the last few lines of an console based applciation using C. Is this possible?

                Comment

                • ppd
                  New Member
                  • Jan 2008
                  • 4

                  #9
                  Hi,
                  I am not sure I understand what you mean, but I will say a few things anyway.

                  If it is a command line program outputting text to the screen or console, can you run this program from the command line
                  and tell it to write to a file? E.G.
                  command.exe > file
                  Then you would have the output in a file which you could
                  read with a C program.

                  If it is a screenshot or image of the entire console that you need, then you can get a screen shot using a command in windows (look in the windows help). It is some key+"Print Screen" that saves a copy of the entire screen of your computer into an image file. Then you are on your
                  own to deal with that.

                  good luck.
                  Last edited by ppd; Jan 23 '08, 04:23 AM. Reason: error

                  Comment

                  Working...