473,804 Members | 3,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9263
On Feb 27, 8:40 pm, "praetor.mich.. .@gmail.com"
<praetor.mich.. .@gmail.comwrot e:
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************ *********@q2g20 00cwa.googlegro ups.com>,
pr************* @gmail.com <pr************ *@gmail.comwrot e:
>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.nr c-cnrc.gc.ca (Walter Roberson)
wrote:
In article <1172608859.551 149.90...@q2g20 00cwa.googlegro ups.com>,

praetor.mich... @gmail.com <praetor.mich.. .@gmail.comwrot e:
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.nr c-cnrc.gc.ca (Walter Roberson)
wrote:
>>In article <1172608859.551 149.90...@q2g20 00cwa.googlegro ups.com>,

praetor.mich. ..@gmail.com <praetor.mich.. .@gmail.comwrot e:
>>>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
applicatio n 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************ **********@t69g 2000cwt.googleg roups.com>,
pr************* @gmail.com <pr************ *@gmail.comwrot e:
>On Feb 27, 4:02 pm, rober...@ibd.nr c-cnrc.gc.ca (Walter Roberson)
wrote:
>In article <1172608859.551 149.90...@q2g20 00cwa.googlegro ups.com>,

praetor.mich.. .@gmail.com <praetor.mich.. .@gmail.comwrot e:
>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.comwrit es:
On Feb 27, 4:02 pm, rober...@ibd.nr c-cnrc.gc.ca (Walter Roberson)
wrote:
>In article <1172608859.551 149.90...@q2g20 00cwa.googlegro ups.com>,
praetor.mich.. .@gmail.com <praetor.mich.. .@gmail.comwrot e:
>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.program mer.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_Keit h) 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.comwrot e 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.in validwrites:
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_Keit h) 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

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

Similar topics

2
1459
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() sys.stderr = sys.__stderr__
3
3762
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 problem is the C++ lib does write stuffs on its stdout, and I would like to print those messages in a Tk frame. When I run the computation, it has it's own thread. So my question is : how van I redirect the dll's stdout to something I can
3
3435
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
1771
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 that could import sys afterwards - so I don't want to make the change in the sys module.
10
7639
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
4643
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, when I run it, it stalls and does nothing. I'm wondering if there's something obvious that I'm missing. My code is below and any help would be appreciated. Thanks, Dave
1
3082
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 calling that function, and then revert the stderr back after calling that function. I have something like this: def nullStderr(): sys.stderr.flush()
10
4073
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 replacing all the perror calls with a custom function ? -- Guillaume Dargaud http://www.gdargaud.net/
1
6704
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 own stderr? Say I have a program called foo: #!/usr/bin/python
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10330
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10319
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10076
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4297
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.