Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-19 23:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found