How to capture standard error output from a Windows service? How to capture standard error output from a Windows service? windows windows

How to capture standard error output from a Windows service?


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.


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

SetStdHandle(STD_ERROR_HANDLE, logFileHandle);