473,382 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 5569
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Count Dracula | last post by:
I narrowed down the source of the error. The stand-alone program listed below reproduces it. The compilation finishes but the warning is too serious to ignore: cl -GX prog.cpp Microsoft (R)...
1
by: sop3k | last post by:
Hello !!! I have a problem during compilation example program from tutorial about MySql++ 1.7.1 When I want to compile that simple program: #include <iostream> #include <iomanip> #include...
1
by: vj | last post by:
I need to capture the error code put out by an executable which I run from my program using rc = system(command); I get the stdout into rc. But how do I get to stderr ? ( command does cerr <<...
2
by: ndessai | last post by:
Hi All, I had a project which used to redirect stderr to a file in VC 6. (working fine) When I ported it to VC 7 it does not put messages in the file. Any ideas??? Thanks,
9
by: Daniel | last post by:
Hi, While I compile my old C++ source in VC.Net, rebulild whole project, there are always some header files are unvaliable like "fstream.h", "Dxguide.h".....etc. Did VC.Net remove the VC++'s...
2
by: rogero | last post by:
I'm having a nasty problem where the destructor of an automatic variable is invoked with the wrong address during stack unwinding. Below is a small example program. Roger Orr -- MVP in C++ at...
1
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
2
by: Peter Duniho | last post by:
On Fri, 18 Jul 2008 10:41:23 -0700, jmDesktop <needin4mation@gmail.com> wrote: Well, that's an interesting example, if for no other reason than that the DirectShow video capture stuff is a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.