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.


In reply to [OT] Environment variable missing for scheduled task in Windows Server 2008 by Lotus1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.