469,632 Members | 1,639 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,632 developers. It's quick & easy.

vc++6.0: capture cerr

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.
Jul 19 '05 #1
6 5417
WW
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++.

--
WW aka Attila
Jul 19 '05 #2
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.


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

Jul 19 '05 #3
"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/>
Jul 19 '05 #4
Dietmar Kuehl wrote:
"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


"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++...

--
Attila aka WW
Jul 19 '05 #5

"Attila Feher" <at**********@lmf.ericsson.se> wrote
Dietmar Kuehl wrote:
"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.

[...]
"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.
Jul 19 '05 #6
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.

--
WW aka Attila
Jul 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Count Dracula | last post: by
1 post views Thread by sop3k | last post: by
2 posts views Thread by ndessai | last post: by
9 posts views Thread by Daniel | last post: by
1 post views Thread by dasilva109 | last post: by
3 posts views Thread by Hamilton Woods | last post: by
2 posts views Thread by Peter Duniho | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.