当前位置: 动力学知识库 > 问答 > 编程问答 >

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: