"WW" <wo***@freemail.hu> wrote:
Mike - EMAIL IGNORED wrote: I have a VC++6.0 program than calls library functions
that write to cerr. I would like to capture this output
in the calling program. Would you please let me know
how I could to this? If I should ask on another group,
please let me know.
You need to. A Microsoft one. Or a POSIX one - if MS really does implement
POSIX as they say the do. The Standard C++ has no support for this. I mean
you can redirect cerr to file (well, not on all MS OSes) and then read that
file, but I think you would rather want something like a pipe. And pipes
are not in standard C++.
If the library really writes to 'std::cerr' rather than writing to the
standard error stream using eg. 'fprintf(stderr, ...)' or 'write(2, ...)',
there is a perfectly portable C++ solution to the problem: it is possible
install a new stream buffer into 'std::cerr' to which all characters written
to 'std::cerr' are sent:
std::ostringstream serr;
std::streambuf* cerr_sbuf = std::cerr.rdbuf();
std::cerr.rdbuf(serr.rdbuf());
// now everything written to 'std::cerr' is captured by serr
cerr.rdbuf(cerr_sbuf); // restore original stream buffer to avoid
// references to deleted objects
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
Phaidros eaSE - Easy Software Engineering: <http://www.phaidros.com/>