[LCP] Redirecting File stream to a char*?

Anton V. Demidov demid at kemsu.ru
Fri Jun 27 12:16:21 EST 2008


Hello, Leonard.

Friday, June 27, 2008, 8:57:43 AM, you wrote:

LS> I need to use a function that is included from a shared library. The
LS> function uses fprint to output errors to stderr or the file pointer
LS> that is passed with the function call. I want to capture the output to
LS> a char* and not be outputed to stdout. I've tried different things,
LS> like using setbuf, but it hasn't been quite right.

LS> Is there a way to do this?

LS> Thanks
LS> Len

LS> _______________________________________________
LS> This is the Linux C Programming List
LS> :  http://lists.linux.org.au/listinfo/linuxcprogramming List

You could try to substitute stderr with another file descriptor using
dup() function (check Maurice Bach's "The design of the UNIX OS" for
detailes). If you shift stderr to a channel file, then you can
readback all standart error output from the channel.

Not sure if it will work. Perhaps this worthless idea caused by my
insomnia (was watching eurocap semifinal last night). But this is the
first solution came to my mind. Will be glad if it's usefull.

-- 
-- 
Anton Demidov
mailto:demid at kemsu.ru




More information about the linuxCprogramming mailing list