When the same application is run in Windows Service mode, even though
the redirecting succeeds I dont see the outputs in my log file. I have
a valid log file and there is no problems in redirecting...Just that
in windows service mode I dont see the output in my redirected file.
Do anybody know what is the mistake Im doing here
Any help is appreciated.
Thanks
Anand
Hi,
if you set the subsystem in your linker settings to WINDOWS instead of
CONSOLE, anything sent to stdout or stderr will be silently
disregarded.
So if you would like to print anything to your logfiles in a
SUBSYSTEM:WINDOWS built, you would have to open your logfile manually
and write to it with e.g. fprintf.
Or you create yourself some macros, which write to stdout/stderr in
your Debug built, which may use SUBSYSTEM:CONSOLE
and to a custom stream in your Release built which may use WINDOWS as
subsystem.
Olli
Here's how Apache did stdin/out dup in Win32
http://www.slink-software.com/W/SrcDoc_Top/apache_1.3.28/apache_1.3.28.sdoc/N_105
/* Open a null handle to nak our stdin */
hNullFile = CreateFile("nul", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
&sa, OPEN_EXISTING, 0, NULL);
if (hNullFile == INVALID_HANDLE_VALUE) {
ap_log_error(APLOG_MARK, APLOG_WIN32ERROR | APLOG_CRIT, NULL,
"Parent: Unable to create null stdin pipe for
this service process.\n");
}
else {
int fh;
FILE *fl;
fflush(stdin);
SetStdHandle(STD_INPUT_HANDLE, hNullFile);
fh = _open_osfhandle((long) STD_INPUT_HANDLE,
_O_RDONLY | _O_BINARY);
dup2(fh, STDIN_FILENO);
fl = _fdopen(STDIN_FILENO, "rcb");
memcpy(stdin, fl, sizeof(FILE));