473,395 Members | 1,393 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,395 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 5570
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.