·  PERL – Support - PerlSvc

 

- Info:

  - PerlSvc utility converts a Perl program to a native Windows service with an .exe extension.

  - There are two types of services that can be generated: 

    - For dependent services ActivePerl must be installed on the target computer.

    - For freestanding services ActivePerl needn't be installed on the target computer.

  - This tutorial is based on:

    http://aspn.activestate.com/ASPN/docs/PDK/6.0/PerlSvc_overview.html

    http://www.gigi.co.uk/guiconsole/servicetest.txt

 

- Procedure:

  -  Create MyService.pl.

 

  -  perlsvc   --verbose myservice.pl

  - Creates a freestanding executable file named myservice.exe

  -  myservice --install

  - MyService installed as MyService Display.

  -  myservice --install auto

  - Installs myservice.exe as a service automaticly loaded at system startup.

  -  net start TestSvc

  - Manually start servic.

  -  net stop  TestSvc

  - Stop & uninstall service.

  -  myservice --remove

  - Remove service.

 

    MyService.pl

    package PerlSvc;

    

    $PerlSvc::Name        = "MyService";        #Short name by which your service is known.

    $PerlSvc::DisplayName = "MyService Display";    #Display name in Windows 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;

      }

    

    }