in reply to Re^2: Turn a perl script into a Win32 Service
in thread Turn a perl script into a Win32 Service

All,
It looks like SrvAny is a bust. The service starts and perl is in the process table, but it doesn't do anything. Even unbuffered output to STDERR in a BEGIN block doesn't show up until after stopping the service and then that's all it does. Still looking for solutions.

Cheers - L~R

  • Comment on Re^3: Turn a perl script into a Win32 Service

Replies are listed 'Best First'.
Re^4: Turn a perl script into a Win32 Service
by BrowserUk (Patriarch) on Oct 14, 2008 at 15:23 UTC
      BrowserUk,
      Here is an idea of what I am talking about (actual code is at home):
      #!/usr/bin/perl BEGIN { open(STDERR, '>', 'C:/app_name/err.log' or die $!; select STDERR; $| = 1; # un-necessary, I know print STDERR "hello world\n"; } use lib 'C:/app_name'; use strict; use warnings; use My::App; my $app = My::App->new(cfg => 'C:/app_name/app.cfg') or die "Didn't ge +t past this point\n"; print STDERR "Ok, got here\n"; while ($app->run_ok) { print STDERR "Inside while loop\n"; $app->do_things(); $app->rest_for_a_while(); } print STDERR "finishing up now\n";

      When I start the service, the err.log file is created but is 0 bytes. After 5 minutes or so, I stop the service and the following output shows up in the err.log file (hello world and Ok, Got here)

      Cheers - L~R

        The following works for me on XP:

        1. Install SrvAny with: instsrv "YourService" c:\the\Path\to\SrvAny.exe
        2. Use Regedit to add the following keys:
          [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SrvAny\Parameter +s] "Application"="\\perl\\bin\\wperl.exe \\test\\service.pl"

          Modify the paths to your wperl and script accordingly.

        3. Go into the Service Manager, double-click "YourService". Select the "Log-on" tab from the properties dialog and check the "Allow service to interact with desktop" option. Apply and save.
        4. This is my minimal service.pl:
          #! perl -slw use strict; use Win32; open LOG, '>', 'c:\test\service.log' or die; select LOG; $|++; Win32::MsgBox( 'From service.pl at ' . localtime, 0, "Service.pl" ); while( sleep 5 ) { Win32::MsgBox( 'From service.pl at ' . localtime, 0, "Service.pl" + ); print scalar localtime; } close LOG;

          It pops up a message box on startup and every 5 seconds thereafter. (And bloody annoying it is too :)

          It creates and writes to the log file.

        YMMV on Vista.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re^4: Turn a perl script into a Win32 Service
by ikegami (Patriarch) on Oct 14, 2008 at 15:40 UTC
    Maybe you'll have better luck using wperl.exe instead of perl.exe.
      ikegami,
      Maybe you'll have better luck using wperl.exe instead of perl.exe.

      Interesting thought. I wonder where you came up with it?

      This application currently doesn't write to STDOUT, STDERR, or read input from STDIN. It does write information to a SQLite database as well as launch external GUI applications (Firefox via WWW::Selenium as well as interface Outlook via Win32::API. It runs fine from the command line but not as a service (no work is performed). I am happy to give wperl.exe a try later but I am not sure why it would work where perl.exe fails.

      Are you thinking that it is specifically my application and not just any perl script that won't work using SrvAny with 5.10 on Vista?

      Cheers - L~R

        It's simpler than that. I am thinking that Perl might attempt to access the console even if it doesn't end being used.