Thread: receiving stderr and stdout from popen

  1. #1
    Registered User
    Join Date
    Aug 2002

    receiving stderr and stdout from popen

    Hello all,

    consider the code for running an external process and receiving the output:
            read_fp = popen(system_call,"r");
            if (read_fp != NULL)
                    chars_read = fread(sys_result, sizeof(char), sizeof(my_var)-1,                      read_fp);	
    i want to be able to receive the stdout stream and not the stderr stream.

    is this done by popen by default, or will i have to change the system_call or the external process?

    i think i've just answered my question!!! maybe cat "2>/dev/null" on the end of system_call???

    i would still like to know about popen though.

    TIA, rotis23

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    You can also use pipe() and fork(), which is what I *believe* popen() does anyway. There's sample code of this somewhere, I thought it was here but it doesn't look like I remember Anyway, it may help you.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getting stderr from an app launched via execv
    By KPexEA in forum Linux Programming
    Replies: 1
    Last Post: 08-16-2008, 10:36 PM
  2. stderr question
    By -EquinoX- in forum C Programming
    Replies: 10
    Last Post: 03-05-2008, 10:32 PM
  3. Redirecting stdout, stderr and stdin
    By iwabee in forum Linux Programming
    Replies: 9
    Last Post: 05-16-2005, 05:42 PM
  4. stderr vs stdout
    By JoshG in forum C Programming
    Replies: 6
    Last Post: 10-20-2002, 11:17 PM