smanicka has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

Here's something I want to throw out.I am feeling real dumb about this.I have a script that I want to run as a win32 service.After looking at a lot of ption (srvany.exe, win32::deamonize etc) I decided that it would probably be a lot easier to just buy PDK 7.5 and use the perlsvc utility to create the service.

i found a tutorial @ http://ivoronline.com/Programming/PERL/Tutorials/PERL%20-%20Support%20-%20PerlSvc.php

so if my code is
#!usr/bin/perl use modules XYZ while(1){ DO ABC }
Where would i place my code in the code that they have provided if i need to get it to run as a service? Their code is
MyService.pl package PerlSvc; $PerlSvc::Name = "MyService"; #Short name by which your service is known. $PerlSvc::DisplayName = "MyService Display"; #Display name in W +indows Control Panel. sub PerlSvc::Startup(){ #Function called when the service is started. my $exitloop = 1; my $sleep = 1; while ($exitloop) { $outputFile = "C:/TEMP/Perl/myservice.log"; if(!open(myOutput, ">>$outputFile ")) { print("Could not open" +.$outputFile); } print(myOutput localtime(time)."\n"); print localtime(time)."\n"; close(myOutput ); sleep $sleep; } }
Thanks -Sandhya

Replies are listed 'Best First'.
Re: perlscv help required.
by Anonymous Monk on Feb 06, 2009 at 19:46 UTC
    I decided that it would probably be a lot easier to just buy PDK 7.5 and use the perlsvc utility to create the service.
    Really? I thought the latest was PDK 7.3, which comes with support...

    Where would i place my code in the code that they have provided if i need to get it to run as a service?
    When the service is started, it will call

    sub PerlSvc::Startup(){ #Function called when the service is started.
    which is where you put your code
      Ok will try that. Please let me rephrase my question though.I wasn't sure if i should also use the while (1), in my code if its going to be a service.Would the program exit after the first time it ran or keep working throughout without the need for the while (1)?I hope I am making sense
Re: perlscv help required.
by Bloodnok (Vicar) on Feb 07, 2009 at 01:58 UTC
    As I've said elsewhere, Dave Roth's book (and website) provides all you need to implement Win32 services in perl - other than using ActiveState PDK - which'll cost you.

    A user level that continues to overstate my experience :-))