I write a lot of Perl scripts that run periodically in the background through the so-called Task Scheduler. Each of these scripts appends to a log file and sends a one-liner to the next-to-useless Event Log to report the path to this log file. I redirect STDOUT and STDERR to the log file so that everthing gets set there. This all works fine using perl.exe but not with wperl.exe the “non console” version of perl.exe. Today I found out why.
In wperl.exe fileno(STDOUT) returns -1, an invalid file handle number. So, you have to close(STDOUT) and then open(STDOUT, “>>$log_file”). In perl.exe I would open(LOGFILE, “>>$log_file”) and then open(STDOUT, “>&LOGFILE”). Now I can run (w)perl scripts at user logon/off and system startup/shutdown events and still have some logs to look at if something goes awry.
Copyright © 2002-2006 James (Jim) R. R. Service (@gmail.com - jservice)