Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Running Perl code from a Windows service

by Anonymous Monk
on Sep 19, 2001 at 01:06 UTC ( [id://113211]=perlquestion: print w/replies, xml ) Need Help??

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

I'm using ActivePerl on Windows 2000. Code like system("myCApplication.exe param1 param2"); works fine when I run it at the command line. However, when this code is run by a Windows service, it fails to call myCApplication. I know that path is not the problem since I have tried hardcoding it. Do I have to open a command sheel in order to do this?
  • Comment on Running Perl code from a Windows service

Replies are listed 'Best First'.
Re: Running Perl code from a Windows service
by Moonie (Friar) on Sep 19, 2001 at 01:33 UTC
(tye)Re: Running Perl code from a Windows service
by tye (Sage) on Sep 19, 2001 at 01:44 UTC

    Services run in interesting security contexts. In WinNT, from the Services control panel you can click "Startup" and request that the server be given access to the desktop (unless you've configured a non-default security context for that service already). This might be the problem that you are having. I'll try to check later if this is the same on Win2K.

            - tye (but my friends call me "Tye")

      A few things: Services can interact with the command line or the network, not both. Services will fail if they must do both.

      Use the srvany.exe to run your perl script as a service.

      ~Hammy
      Ommmmm.....

        Services can interact with the command line or the network
        I think you mean desktop as opposed to command line.

        By default, the service will probably run as LocalSystem - which has the option of accessing the desktop, but can't access the network. If you run it as a domain\workgroup user, it will be able to access the network and it will be able to spawn processes, but they won't be visible to the interactive user.

        Finally, I prefer Win32::Daemon to srvany.exe - It's a bit more work, but so much more powerful.

        update: No. I don't have shares in Dave Roth!

        _________________________________________
        Simon Flack ($code or die)
        $,=reverse'"ro_';s,$,\$,;s,$,lc ref sub{},e;$,
        =~y'_"' ';eval"die";print $_,lc substr$@,0,3;
Re: Running Perl code from a Windows service
by jbert (Priest) on Sep 19, 2001 at 20:31 UTC
    The usual gotcha I find is that the services do not set the environment variables of the user they run as. Often this is the PATH, but you've covered that.

    However, some external executables require their own environment variables to be set to work. You happily check that a given user account has them set, you happily set the service to run as that user, you log in as that user and check it all runs OK. But it doesn't work as a service.

    So...check the environment of the user for which your script works and try setting likely things in %ENV before you run the command.

    If nothing looks likely, you can eliminate this as the potential issue by simply importing the entire environment. Run a 'set > env.txt' command in a command prompt as the user which this works for, and then do something along the lines of:

    open( ENVFILE, "< env.txt" ) or die_screaming_in_agony(); %ENV = map( split /=/, $_, 2 } <ENVFILE>; # Untested, looks cool thoug +h
    Good luck.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://113211]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-23 07:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found