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

I am trying to turn a script I have running on Windows 2000 into a Windows Service. I can create the service and run it with no problem but one of my system calls that works in an interactive session does not get any return information when executing as a service. The code does an rcmd (remote call to another server) and executes a command to get information back on a proceses memory utilization. This is the line of code that runs the command:
$status=`rcmd \\\\$servers[$i] tlist $pid | findstr Working`;
When running as a service the $status variable comes up empty, but in an interactive session it has the info I need. Any suggestions on how to get this information back? Also the service is running as a user with the permissions needed to execute the command. Thanks.

Replies are listed 'Best First'.
Re: Getting Results back from System Call
by halley (Prior) on Aug 08, 2003 at 19:01 UTC
    There's two basic choices.
    $status = system("command");
    or
    $output = `command`;
    Pick the one you use, based on what you need to collect.

    (If you're trying to say that your command is not working properly when invoked through a perl script (as opposed to being invoked interactively at the shell prompt), then it may be sensitive to whether its STDIN is attached to an interactive device like a tty. But that wasn't completely clear from your question.)

    --
    [ e d @ h a l l e y . c c ]

      The command runs in a Perl script when that script is run from a command prompt and not as a service. To run it as a service I am using the PDK and running perlsvc script.pl to create an executable and then installing that executable using script.exe -install. If I run script.exe from cmd it works fine when I run the service is when the rcmd command fails.

        Your problem is almost certainly a permissions thing.

        Windows NT services run as LocalSystem by default. LocalSystem is a predefined local account and any service running under LocalSystem:

        • The service can NOT open HKEY_CURRENT_USER .
        • The service can open HKEY_LOCAL_MACHINE\SECURITY.
        • The service has no network credentials and can only access network resources using a null session.

        As rcmd requires network access, if the service was set up with the default "LocalSystem" account, then it won't have the privaleges required to run rcmd. This is not a perl problem.

        'Hidden' within this readmore is non-perl related assistance.


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
        If I understand your problem, I can solve it! Of course, the same can be said for you.

Re: Getting Results back from System Call
by BrowserUk (Patriarch) on Aug 08, 2003 at 19:04 UTC

    How are you running the perl script as a service?


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
    If I understand your problem, I can solve it! Of course, the same can be said for you.

Re: Getting Results back from System Call
by traveler (Parson) on Aug 08, 2003 at 20:00 UTC
    I would check halley's idea that it might be an issue that tlist needs some kind of stdin. Then I'd log $i, $servers[$i], $pid to a file to see if they are what you expect.

    --traveler

A reply falls below the community's threshold of quality. You may see it by logging in.