So, in C, is there a way to capture the stdout from a function?

I have FunctionX which printfs a bunch of stuff. I'd like to capture that stuff
into a string without it printing and do a bunch of modifications to it before
printing.

Did that make sense? Any ideas how I can do that? 

MRB

p.s.

I know if I wanted to capture the contents of a system call, I could use
popen(), something like what I have below, but is there a way, in C to do this
with a C function?

#define bufsize 1024

FILE *pp;
char VBUFF[bufsize];

...

if ((pp = popen( "/sbin/mount -va 2<&1","r")) == NULL)
   {
   printf("Failed to open pipe\n");
   return errorcode;
   }
 
while (!feof(pp))
   {
   fgets(VBUFF,bufsize,pp);

   /* Just write the output to stdout */

   printf ("Pipe read: %s\n",VBUFF);
   }
 
pclose(pp);


____________________
BYU Unix Users Group 
http://uug.byu.edu/ 
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list

Reply via email to