Debugging the Service
If all goes well, your Win32 Perl service will run smoothly. However, problems can arise, and you might need to debug the service.
Win32 services have limitations that can be difficult to work around. The biggest limitation is that a service runs headless, which means it doesn't have a UI. Thus, Win32 services are difficult to debug because they don't have any windows that display information, so you can't directly interact with the services. This limitation can be especially frustrating for Perl scriptwriters because they typically use an interactive debugger to debug their scripts.
The most practical way to debug a Win32 Perl service is to have it write debug messages to a log file. You can then examine the log file to see the data that your script printed out. However, this type of debugging is slow and cumbersome because you have to walk through a potentially long log file just to see the results of debug messages. A better alternative is to run SysLogD.pl, which you can find in the Code Library. SysLogD.pl is quite beneficial when debugging a Win32 service because the service writes debugging messages to a named pipe rather than a log file. A named pipe acts as a medium between two processes: the server process that creates the named pipe and the client process that connects to the named pipe. From the viewpoint of both applications, the named pipe looks like a file that they can write to or read from.
SysLogD.pl uses the Win32::Pipe extension (which comes with ActiveState's ActivePerl) to create the named pipe. After creating the named pipe, the script waits for an application to connect to it. A perfect example of a client application connecting to the named pipe is a Win32 service that uses the named pipe as a log file.
After an application connects to the named pipe, the script reads from the named pipe while the client is still connected. The call to the named pipe's Read() function is a blocking call. Therefore, the Read() function won't return anything until the client application has either written data to the named pipe or disconnected from the named pipe. If the application wrote data to the named pipe, the Read() function returns the data. SysLogD.pl displays anything that a client application might send to it. If the application disconnected from the named pipe, the Read() function returns nothing at all.
To test SysLogD.pl, run the script in a cmd.exe window. Then, in another cmd.exe window, run the following Dir command, which redirects the output to the named pipe:
Dir C:\*.* > \\YourMachineName pipe\syslog
Be sure to replace YourMachineName with your computer's name. The result is a directory listing in the Perl script's cmd.exe window.
Because named pipes work over a network, you can have your scripts log to a remote machine. If you have all your services on all your servers log to one remote machine, you would need to monitor only one computer to monitor an entire network of services.
Win32 Services for Everyone
Win32 services are incredibly powerful tools that you shouldn't be without. When you use Perl scripts, creating Win32 services is easy. So, have some fun and create some Win32 services. Drop me an email message sharing the kinds of Perl-based Win32 services that you've created.
End of Article
Prev. page
1
2
3
[4]
next page -->