简体   繁体   中英

install perl script as windows service

I am trying to get a Perl script to install as a Windows service. The Perl code for the purpose of experimentation is very simple (see below)

my $num = 1;

while( $num == 1 )
{
    open(FH, ">>", "C:\\Perl\\MyCode\\Service\\svclog.txt");
    print FH "hello world\n";
    close(FH);
    sleep 3;
}

I have been trying to install the script using the native Windows SC commands...

SC CREATE MyPerlService binpath= "C:\Perl\bin\perl.exe C:\Perl\MyCode\Service\perlsvc.pl" error= normal start= auto DisplayName= "My Perl Service" type= own

The service installs fine. BUT I try to start it up and get a message telling me the service failed to start in the allocated time.

It goes without saying that I know very little about Windows services. I suspect that Windows is waiting for a start() type function to execute but I'm just guessing here. Having said that I'd kind of expect Windows to check/cater for that when it installs the service ??? Dunno :)

I can't use any 3rd party products really, as this is internal to work and there is a whole software ordering process that takes months and months. Ideally I need something that I could use/write that comes with native Windows XP/2003 or Perl 5.8.8 (old versions - yes)

If anyone can point me in the direction of an example of a Perl (or DOS) script that has been installed as a windows service and the code that installed it - I would be very grateful.

for info - I've scoured the Web and a lot of people are talking about using INSTSRV and SRVANY or the PDK - All of which I have no access to at the moment.

Thank you

Trevor

For what it's worth, SRVANY is pretty limited. It can't stop the service, for example. I'd recommend looking at nssm . I have a cpan module that makes it easier to use called Win32::ServiceManager .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM