I am attempting to use Win32::daemon to create a windows service. To start off easy, i installed a windows service using the code found on the html documentation for Win32::daemon.
use Win32::Daemon;
%Hash = (
name => 'PerlTest',
display => 'Oh my GOD, Perl is a service!',
path => 'c:\perl\bin\perl.exe',
user => '',
pwd => '',
parameters =>'c:\perl\scripts\service.pl',
);
if( Win32::Daemon::CreateService( \%Hash ) )
{
print "Successfully added.\n";
}
else
{
print "Failed to add service: " . Win32::FormatMessage( Win32:
+:Daemon::GetLastError() ) . "\n";
}
This installed the service fine with no errors.
Then I tried to use the example service code:
use Win32::Daemon;
# Tell the OS to start processing the service...
Win32::Daemon::StartService();
# Wait until the service manager is ready for us to continue...
while( SERVICE_START_PENDING != Win32::Daemon::State() )
{
sleep( 1 );
}
# Now let the service manager know that we are running...
Win32::Daemon::State( SERVICE_RUNNING );
# Okay, go ahead and process stuff...
open (OUT, ">>C:\perl\scripts\out.txt");
print OUT "Hello, World!";
close OUT;
# Tell the OS that the service is terminating...
Win32::Daemon::StopService();
But I am getting an error saying that the service started and stopped, and the file is not being opened. Please Help!