vc++6.0: capture cerr

  • Thread starter Mike - EMAIL IGNORED
  • Start date
M

Mike - EMAIL IGNORED

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.
Thanks in advance,
Mike.
 
W

WW

Mike said:
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++.
 
R

Ryan Winter

Mike said:
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.

Take a look at this page. It describes (in a round about way) how to
reassign standard streams to whever you would like.

http://www.noasia.net/taowen/classic/004/2001_3.htm
 
D

Dietmar Kuehl

WW said:
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::eek:stringstream 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
 
A

Attila Feher

Dietmar said:
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::eek:stringstream 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

"I would like to capture this output in the calling program."

Do you know any standard IPC mechanism in C++? Just because you say that it
can be done using standard C++...
 
B

Buster

Attila Feher said:
[...]

"I would like to capture this output in the calling program."

Do you know any standard IPC mechanism in C++? Just because you say that it
can be done using standard C++...

Read it again. The calling program "calls library functions";
there is no mention, explicit or otherwise, of multiple processes.

Regards,
Buster.
 
W

WW

Buster wrote:
[SNIP]
Read it again. The calling program "calls library functions";
there is no mention, explicit or otherwise, of multiple processes.

You are right. My English is even worse than I thought. Thanx for the
clarification.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top