Tuesday, March 11, 2008

Problems with Windows Universal Agent Perl scripts

Have you every had a Perl script running from a Windows Universal Agent not perform as expected but run correctly from the command line?

Here is a possible solution.

The issue I have found running ActivePerl scripts as Universal Agents is that the SYSTEMROOT environment variable is not set. An example of errors you may experience is the message "Bad protocol ('tcp')" when using the LWP::UserAgent module.

I wrote a UA that dumped the %ENV hash and found that the only variables defined were:
MONITOR_ID
PROBE_ID
HOSTNAME
INTERP
MONITOR
PROBE_ARG
PROBE
PREV_VALUE
LASTSTAMP

First I tried editing the KUMENV file with no success.

Next I tried using the envfile option to the //SOURCE entry in the metafile. Again, no luck.

The only method I have found that works consistently is to manually set the SYSTEMROOT variable using $ENV{SYSTEMROOT}="C:\\WINDOWS" from within the script.

Perhaps there is another way and if I manage to discover it or if someone beats me to it , I will provide an update.

No comments: