473,406 Members | 2,369 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,406 software developers and data experts.

Redirecting stderr

I have a DLL written in C that writes to stderr. I have a win32
console application that makes calls to the DLL. In the console app I
redirect stderr to a file using freopen. The problem I'm having is
that none of the messages sent to stderr from the DLL are getting
written to the file but if I write to stderr from the console
application it gets written to the file no problem. Any ideas??

Feb 27 '07 #1
18 9228
On Feb 27, 8:40 pm, "praetor.mich...@gmail.com"
<praetor.mich...@gmail.comwrote:
I have a DLL written in C that writes to stderr. I have a win32
console application that makes calls to the DLL. In the console app I
redirect stderr to a file using freopen. The problem I'm having is
that none of the messages sent to stderr from the DLL are getting
written to the file but if I write to stderr from the console
application it gets written to the file no problem. Any ideas??

Several ideas:

1) Ask in an appropriate newsgroup.
2) Library functions should not write to the stderr
stream. You should consider redesigning them.
3) When you follow the advice given in #1, give
more details.

--
Bill Pursell

Feb 27 '07 #2
In article <11*********************@q2g2000cwa.googlegroups.c om>,
pr*************@gmail.com <pr*************@gmail.comwrote:
>I have a DLL written in C that writes to stderr. I have a win32
console application that makes calls to the DLL. In the console app I
redirect stderr to a file using freopen. The problem I'm having is
that none of the messages sent to stderr from the DLL are getting
written to the file but if I write to stderr from the console
application it gets written to the file no problem. Any ideas??
That sounds like a question more appropriate for a Windows
programming newsgroup. In this newsgroup, comp.lang.c, we can
tell you about how freopen() is supposed to work, but interactions
with system routines such as DLLs are beyond the scope of the C
language itself.

--
Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson
Feb 27 '07 #3
On Feb 27, 4:02 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
wrote:
In article <1172608859.551149.90...@q2g2000cwa.googlegroups.c om>,

praetor.mich...@gmail.com <praetor.mich...@gmail.comwrote:
I have a DLL written in C that writes to stderr. I have a win32
console application that makes calls to the DLL. In the console app I
redirect stderr to a file using freopen. The problem I'm having is
that none of the messages sent to stderr from the DLL are getting
written to the file but if I write to stderr from the console
application it gets written to the file no problem. Any ideas??

That sounds like a question more appropriate for a Windows
programming newsgroup. In this newsgroup, comp.lang.c, we can
tell you about how freopen() is supposed to work, but interactions
with system routines such as DLLs are beyond the scope of the C
language itself.

--
Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson
It actually works the same on either platforms. The code was designed
to work on windows and all unix flavors. Which is why I posted it
here.

As for the library code not writing to stderr where do you suggest an
error message get printed to?? That's the whole point of the sterr
stream.

As for your comment (Bill) on more details, what more do you want??

Feb 27 '07 #4
pr*************@gmail.com wrote:
On Feb 27, 4:02 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
wrote:
>>In article <1172608859.551149.90...@q2g2000cwa.googlegroups.c om>,

praetor.mich...@gmail.com <praetor.mich...@gmail.comwrote:
>>>I have a DLL written in C that writes to stderr. I have a win32
console application that makes calls to the DLL. In the console app I
redirect stderr to a file using freopen. The problem I'm having is
that none of the messages sent to stderr from the DLL are getting
written to the file but if I write to stderr from the console
application it gets written to the file no problem. Any ideas??

That sounds like a question more appropriate for a Windows
programming newsgroup. In this newsgroup, comp.lang.c, we can
tell you about how freopen() is supposed to work, but interactions
with system routines such as DLLs are beyond the scope of the C
language itself.
*Please trim signatures!*
>
It actually works the same on either platforms. The code was designed
to work on windows and all unix flavors. Which is why I posted it
here.
You didn't post any code. As soon as people see 'DLL' their platform
specific auto responders kick in!

Post an example if you can.

--
Ian Collins.
Feb 27 '07 #5
In article <11**********************@t69g2000cwt.googlegroups .com>,
pr*************@gmail.com <pr*************@gmail.comwrote:
>On Feb 27, 4:02 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
wrote:
>In article <1172608859.551149.90...@q2g2000cwa.googlegroups.c om>,

praetor.mich...@gmail.com <praetor.mich...@gmail.comwrote:
>I have a DLL written in C that writes to stderr. I have a win32
console application that makes calls to the DLL.
>That sounds like a question more appropriate for a Windows
programming newsgroup.
>It actually works the same on either platforms. The code was designed
to work on windows and all unix flavors. Which is why I posted it
here.
That's bogus. There's no DLL support in the Unix version I use,
and it is one of the few officially certified Unix releases.
If you search opengroup.org (official certifiers of Unix),
you will find that the DLL references are all platform specific.

Whatever it is you are using is *not* part of standard C -- and
if it is called "DLL", it is not even part of standard Unix,
nor POSIX. If the code uses DLLs on Windows and shared libraries
on the POSIX-compatible Unix systems, then it it is using something
platform specific, not part of the C language.

Note, by the way, the official opengroup definition of dlopen()
http://www.opengroup.org/onlinepubs/...ns/dlopen.html

The dlopen() function shall make an executable object file
specified by file available to the calling program. The class of
files eligible for this operation and the manner of their
construction are implementation-defined, though typically such
files are executable objects such as shared libraries,
relocatable files, or programs.

Notice the lack of reference to DLL. That is not an accident:
C doesn't have them and POSIX doesn't have them either.
--
"No one has the right to destroy another person's belief by
demanding empirical evidence." -- Ann Landers
Feb 27 '07 #6
"pr*************@gmail.com" <pr*************@gmail.comwrites:
On Feb 27, 4:02 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
wrote:
>In article <1172608859.551149.90...@q2g2000cwa.googlegroups.c om>,
praetor.mich...@gmail.com <praetor.mich...@gmail.comwrote:
>I have a DLL written in C that writes to stderr. I have a win32
console application that makes calls to the DLL. In the console app I
redirect stderr to a file using freopen. The problem I'm having is
that none of the messages sent to stderr from the DLL are getting
written to the file but if I write to stderr from the console
application it gets written to the file no problem. Any ideas??

That sounds like a question more appropriate for a Windows
programming newsgroup. In this newsgroup, comp.lang.c, we can
tell you about how freopen() is supposed to work, but interactions
with system routines such as DLLs are beyond the scope of the C
language itself.
Please don't quote signatures. Trim quoted material to what's
necessary for your followup to make sense to someone who hasn't read
the parent article.
It actually works the same on either platforms. The code was designed
to work on windows and all unix flavors. Which is why I posted it
here.
Windows and Unix are just two out of many platforms. DLLs, I believe,
are specific to Windows; Unix has something similar (shared
libraries). Neither feature is defined by standard C, which is what
we discuss here.

If you post to a Windows-specific group, perhaps
comp.os.ms-windows.programmer.win32 or one of the microsoft.* groups,
they can help you with your DLL issues; whatever solution you get
there may or may not be applicable to Unix (or to any other system).
As for the library code not writing to stderr where do you suggest an
error message get printed to?? That's the whole point of the sterr
stream.
Generally, printing error messages should be up to the program that
uses a library, not the library itself. A library routine, if it's to
be generally useful, should probably return information to the caller
indicating whether there was an error; it's up to the application to
decide what to do with that information.

For example, the standard fopen() function is part of the standard C
library. If it fails, it doesn't print an error message; it returns a
null pointer to let the caller know that it failed. (On some systems,
it may also set errno to provide more information about the failure.)

Imagine a version of fopen() that prints a message on any error, and
imagine a program that wants to open "foo.txt" if it exists, otherwise
"bar.txt":

/* ... */
FILE *f;
f = fopen("foo.txt", "r");
if (f == NULL) {
f = fopen("bar.txt", "r");
}
/* ... */

Failure to open "foo.txt" isn't an error as far as the program is
concerned, and the program knows that no error message is needed.
This hypothetical fopen() would just annoy the user with spurious
error messages.
As for your comment (Bill) on more details, what more do you want??
Complete, compilable sources for the program would be a good start.
Trim the program down to the minimum that exhibits the problem. If
the stripped version of the program is over, say, 100 lines or so,
consider posting a link to the source rather than the source itself.
And since your program depends on features that go beyond standard C,
you'll need to do this in some other newsgroup.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Feb 27 '07 #7
Keith Thompson said:

<snip>
DLLs, I believe,
are specific to Windows;
Nah - mainframes had DLLs when Windows was still just a gleam in Bill
Gates's wallet.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Feb 27 '07 #8


<pr*************@gmail.comwrote in message
>I have a DLL written in C that writes to stderr. I have a win32
console application that makes calls to the DLL. In the console app I
redirect stderr to a file using freopen. The problem I'm having is
that none of the messages sent to stderr from the DLL are getting
written to the file but if I write to stderr from the console
application it gets written to the file no problem. Any ideas??
The standard input and output streams have been vandalised in MSVC++.
My solution to this problem is to knock up a console and provide the
function Con_Printf(), which allows output for debug prurposes. It can even
be used in production runs in certain circumstances.

I can send you the code on request.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Feb 27 '07 #9
Richard Heathfield <rj*@see.sig.invalidwrites:
Keith Thompson said:
<snip>
>DLLs, I believe,
are specific to Windows;

Nah - mainframes had DLLs when Windows was still just a gleam in Bill
Gates's wallet.
Ok, so they're specific to Windows *and* to mainframes. Or something.

(<OT>I *finally* got around to updating my sig.</OT>)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Feb 27 '07 #10
"Malcolm McLean" <re*******@btinternet.comwrites:
<pr*************@gmail.comwrote in message
>>I have a DLL written in C that writes to stderr. I have a win32
console application that makes calls to the DLL. In the console app I
redirect stderr to a file using freopen. The problem I'm having is
that none of the messages sent to stderr from the DLL are getting
written to the file but if I write to stderr from the console
application it gets written to the file no problem. Any ideas??
The standard input and output streams have been vandalised in MSVC++.
My solution to this problem is to knock up a console and provide the
function Con_Printf(), which allows output for debug prurposes. It can
even be used in production runs in certain circumstances.
"Vandalised"? How so? (I claim this is at least marginally topical
if it pertains to whether MSVC++ is a conforming hosted C
implementation.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Feb 27 '07 #11
Keith Thompson said:
(<OT>I *finally* got around to updating my sig.</OT>)
Oh, well played, sir!

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Feb 28 '07 #12
Keith Thompson said:

<snip>
[...] whether MSVC++ is a conforming hosted C implementation.)
In console mode, it is a conforming hosted C implementation - modulo
tiny bugs in dark corners of the language, such as have been reported
once or twice in this newsgroup.

In GUI mode, AFAICT it is a conforming *freestanding* implementation.
The freestandingness can be deduced trivially from the fact that the
entry point in GUI mode is WinMain rather than main. IIRC freestanding
implementations are not required to provide a stderr at all.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Feb 28 '07 #13
"pr*************@gmail.com" wrote:
>
I have a DLL written in C that writes to stderr. I have a win32
console application that makes calls to the DLL. In the console app I
redirect stderr to a file using freopen. The problem I'm having is
that none of the messages sent to stderr from the DLL are getting
written to the file but if I write to stderr from the console
application it gets written to the file no problem. Any ideas??
What is a DLL? What is a "win32 console application"? None of
these are mentioned anywhere in the C standard. I.E. you are off
topic here, and should go to some newsgroup that discusses your
peculiar system. I suspect the group name may include "windows".
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Feb 28 '07 #14

"Keith Thompson" <ks***@mib.orgwrote in message
>The standard input and output streams have been vandalised in MSVC++.
"Vandalised"? How so? (I claim this is at least marginally topical
if it pertains to whether MSVC++ is a conforming hosted C
implementation.)
Put a printf() somewhere into an MSVC program. It ought to compile and link
without complaining. Then you will find that your output simply vanishes. I
presume there is some way of capturing it, but I have never worked out how
to do it.

Vandalism is damage inflicted either pointlessly or for the sake of social
posturing, that falls short of total destruction of the object. I'd say the
treatment of stdio qualifies.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
Feb 28 '07 #15
"pr*************@gmail.com" wrote:
>
I have a DLL written in C that writes to stderr. I have a win32
console application that makes calls to the DLL. In the console app I
redirect stderr to a file using freopen. The problem I'm having is
that none of the messages sent to stderr from the DLL are getting
written to the file but if I write to stderr from the console
application it gets written to the file no problem. Any ideas??
Windows specificalities aside...

How do you know that the library you are calling actually uses the
stream pointed to by stderr?

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Feb 28 '07 #16
On Feb 28, 1:38 pm, Kenneth Brody <kenbr...@spamcop.netwrote:
"praetor.mich...@gmail.com" wrote:
I have a DLL written in C that writes to stderr. I have a win32
console application that makes calls to the DLL. In the console app I
redirect stderr to a file using freopen. The problem I'm having is
that none of the messages sent to stderr from the DLL are getting
written to the file but if I write to stderr from the console
application it gets written to the file no problem. Any ideas??

Windows specificalities aside...

How do you know that the library you are calling actually uses the
stream pointed to by stderr?

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody |www.hvcomputer.com| #include |
| kenbrody/at\spamcop.net |www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:ThisIsASpamT...@gmail.com>
good question... i was under the impression that there was only one
stderr stream... correct me if i'm wrong though...
if there is more than one stderr stream then how would you go about
redirecting it??
would a function inside the library that returned the handle be the
(quick and dirty) solution?

-M

Mar 1 '07 #17
"pr*************@gmail.com" wrote:
>
On Feb 28, 1:38 pm, Kenneth Brody <kenbr...@spamcop.netwrote:
"praetor.mich...@gmail.com" wrote:
I have a DLL written in C that writes to stderr. I have a win32
[...]

Windows specificalities aside...

How do you know that the library you are calling actually uses the
stream pointed to by stderr?

good question... i was under the impression that there was only one
stderr stream... correct me if i'm wrong though...
There is only one "stderr", but who says that the library is using
"stderr" as the stream?

However, there are Windows-specific file handles which are not
necessarily the ones pointed to by "stderr". If the library is
using Windows-specific API calls to access Windows-specific file
handles, then you will need a Windows-specific answer from a
Windows-specific newsgroup. (Hint -- if you have access to the
library source, look for calls to GetStdHandle.)

However, unless you have access to the library source, or can get
an answer to the question of "how does the library send its output"
by other means, you can only guess.

[...]

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Mar 1 '07 #18
On Mar 1, 2:32 pm, Kenneth Brody <kenbr...@spamcop.netwrote:
"praetor.mich...@gmail.com" wrote:
On Feb 28, 1:38 pm, Kenneth Brody <kenbr...@spamcop.netwrote:
"praetor.mich...@gmail.com" wrote:
I have a DLL written in C that writes to stderr. I have a win32
[...]
Windows specificalities aside...
How do you know that the library you are calling actually uses the
stream pointed to by stderr?
good question... i was under the impression that there was only one
stderr stream... correct me if i'm wrong though...

There is only one "stderr", but who says that the library is using
"stderr" as the stream?

However, there are Windows-specific file handles which are not
necessarily the ones pointed to by "stderr". If the library is
using Windows-specific API calls to access Windows-specific file
handles, then you will need a Windows-specific answer from a
Windows-specific newsgroup. (Hint -- if you have access to the
library source, look for calls to GetStdHandle.)

However, unless you have access to the library source, or can get
an answer to the question of "how does the library send its output"
by other means, you can only guess.

[...]

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody |www.hvcomputer.com| #include |
| kenbrody/at\spamcop.net |www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:ThisIsASpamT...@gmail.com>
I wrote the library and I have the source and I know that it prints to
stderr because the messages are being sent in the following line of
code:

fprintf( stderr, "Error...) );

So since that is the case and there is only one stderr stream then why
aren't the messages from the library being sent to the file when I
redirect the stderr stream to a file using the following line of code:

freopen( "stderr.txt", "w", stderr );

That clear up things abit??

Mar 2 '07 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Michele Simionato | last post by:
Maybe it is something obvious, but what is going on with this code? import sys myerr = file("myerr.txt", "w") sys.stderr = myerr try: raise Exception, "some error" finally: myerr.close()...
3
by: David Douard | last post by:
Hi everybody, let me explain by problem: I am working on an application which consists in a C++ dll (numeric computations) and a Python IHM (Python/Tk), which must run under Linux and win32. My...
3
by: Laszlo Zsolt Nagy | last post by:
Hello, I have this code: s = smtplib.SMTP() s.set_debuglevel(1) s.connect(host=smtp_host) s.set_debuglevel(0) log("Connected, sending e-mail") sys.stdout.flush()
9
by: Fuzzyman | last post by:
Hello, I'm trying to redirect standard out in a single namespace. I can replace sys.stdout with a custom object - but that affects all namespaces. There will be code running simultaneously...
10
by: SamG | last post by:
How could i make, from inside the program, to have the stdout and stderr to be printed both to a file as well the terminal(as usual).
116
by: dmoran21 | last post by:
Hi All, I am working on a program to take input from a txt file, do some calculations, and then output the results to another txt file. The program that I've written compiles fine for me, however,...
1
by: reubendb | last post by:
Hello, I have some function that output too much stuff to stderr when called, and I have no control over the function itself. So I thought as a workaround, I redirect stderr to /dev/null before...
10
by: Guillaume Dargaud | last post by:
Hello all, I have some error checking using the function 'perror', which writes messages on stderr. I'd like to send all error messages to a file instead. Is there some way to do this, short of...
1
by: Lincoln Yeoh | last post by:
Hi, I've just started to learn python (I've been using perl for some years). How do I redirect ALL stderr stuff to syslog, even stderr from external programs that don't explicitly change their...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.