#  DaemonDebugPipeClientFunctions.pl
#  Example 8.13:
#  ----------------------------------------
#  From "Win32 Perl Scripting: Administrators Handbook" by Dave Roth
#  Published by New Riders Publishing.
#  ISBN # 1-57870-215-1
#
#  This script is used to debug a Win32 service script. The service
#  opens first calls StartLog() at the beginning of the script. Then
#  anytime it needs to dump debug data it passes the data into 
#  the Log() function.
#  Note: You must change the "machinename" in line 20 to reflect
#        then name of the machine running named pipe server
#        script DaemonDebugPipe.pl (Example_8_12.pl)
#
print "From the book 'Win32 Perl Scripting: The Administrator's Handbook' by Dave Roth\n\n";


sub StartLog
{
    my $Machine;
    $Machine = "." unless( $Machine = shift @_ );
    # Replace "machinename" with the name of the machine that the
    # logging named pipe script runs on.
    if( open( DEBUG_LOG, "> \\\\$Machine\\pipe\\Debug Logging" ) )
    {
        my $OutputHandle = select( DEBUG_LOG );
        $| = 1;
        select( $OutputHandle );
    }
}
 
sub Log
{
    my( $Message ) = @_;  
    print DEBUG_LOG "$Message\n" if( fileno( DEBUG_LOG ) );
}
