views:

542

answers:

2

I have an application that makes use of the Mozilla LDAP library. We're diagnosing a problem involving the LDAP library failing to make a connection to the server. I'm attempting to get additional information from the LDAP library by tossing a debug version of the lib in with the application and enabling debug using ldap_set_opt. Unfortunately, I think the debug library is sending debug strings to standard error.

While I'm working on recompiling the LDAP client library again, hopefully enabling the option that makes it call OutputDebugString instead of streaming to stderr, a nice solution would be to capture the stderr output to a file. The application, though, is running as a Windows service.

Anyone know how I could redirect stderr to a file for an application running as a service?

edit

I'm hoping not to have to modify any more of the service source code than I already have. Options in the service configuration would be ideal.

+2  A: 

If you are modifying the code to the service, you could call SetStdHandle in your ServiceMain:

SetStdHandle(STD_ERROR_HANDLE, logFileHandle);
Michael
+2  A: 

Can you try manually redirecting stderr?

    FILE* stderr_redirect = freopen( "C:/stderr.log", "w", stderr );

    // Code that writes to stderr

    fclose( stderr_redirect );

Edit:

There is no way to redirect stdout or stderr for a service other than to handle those streams inside your service yourself. Some services provide an option to redirect these messages to a file. You could either temporarily redirect these streams or add an option to your service to make it configurable next time you have a problem.

Naaff
hmm... well, thanks for the confirmation Naaff. I guess I'll get to work.
veefu