http://qs321.pair.com?node_id=1216125

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

This is off topic but someone here might have seen this issue. I wrote a Perl script and set it up to run as a scheduled task with the SYSTEM user. I exported the task then imported and installed the script on some Windows 2012 servers with no problems. On a 2008 server my script complained that an environment variable is missing. I had put in a test to check for it.

if( not defined $ENV{SERVER_ENVIRONMENT} or not $ENV{SERVER_ENVIRONMEN +T} ) { print $fh_log "Environment variable \"SERVER_ENVIRONMENT\" is requ +ired to be set up. \n"; die "Environment variable \"SERVER_ENVIRONMENT\" is required to be + set up. \n"; }

The environment variable was added at the system level and I verified the spelling. I wrote this script to see what the SYSTEM user in the scheduled task has access to:

use strict; use warnings; my $logfile = 'test_env.log'; open my $fh_log, ">", $logfile or die "Couldn't open $logfile for outp +ut: $!\n"; print $fh_log "Ran at: ", scalar localtime, "\n"; print "Ran at: ", scalar localtime, "\n"; foreach (sort keys %ENV) { print $fh_log "$_ $ENV{$_}\n"; }

The environment variable is not there in the output of this script when run as a task for the SYSTEM user. The task was exported from Server 2012 and imported into 2008 so all the settings are the same. The original script runs fine from the command line. Any ideas or suggestions?

One more thing, I'm using the portable version of Strawberry Perl so the task runs as d:\portableperl\portableshell.bat d:\scripts\myscript.pl.