SPUG: Perl and setting environment variables

Parr, Ryan Ryan.Parr at wwireless.com
Tue Sep 10 16:05:50 CDT 2002


I use the method of setting %ENV in a script which calls to the database to
collect information about clients and their sites, sets environment
variables used by AwStats, and then uses system() to run reports for the
websites on the system. It does work properly. Try out the following
quickie...

#!/usr/bin/perl

use strict;
$ENV{CHEEKY_FELLOW} = 'Yeah baby yeah!';
system('printenv');

__END__

After the script runs if you do 'printenv' again, the variable isn't there.
Using system() without shell characters even causes it to bypass the shell
altogether. But testing it with system('printenv | less') show that passing
through a shell doesn't affect this process much. It also works using
backticks.

I've never done this on anything other than FreeBSD and Linux, and only with
Perl 5.6.1.  I don't know if there are any gotchas with other systems or
perls.

-- Ryan

-----Original Message-----
From: Timm Gleason [mailto:timm at gleason.to]
Sent: Tuesday, September 10, 2002 12:38 PM
To: spug-list at pm.org
Subject: SPUG: Perl and setting environment variables


I see that there a explicit tools for importing and manipulating
environment variables with Perl, but I need to set them from with a Perl
script and have them passed to all subsequent child processes and shells
that may be executed just as if they were set before the script was
executed.

It was recommended that I use a shell script to set all the EVs and then
invoke the Perl script, however, I do not have all the EV values until
after the script is executed.

I have set them in the script

$ENV{"CVSROOT"} = $CVSROOT;
$ENV{"TMPDIR"} = $TMPDIR;
$ENV{"DIST_ROOT"} = $DIST_ROOT;
$ENV{"BuildNumber"} = $BuildNumber;

but when I execute a command outside of the script, such as with a
system(), the EVs do not get inherited by the child process.


Tuesday, September 10 2002
--                              | To be, or not to be. *BOOM!* Not to
Timm Gleason                    | be.
http://www.gleason.to/          |
http://www.uranushertz.to/      |
Quis custodiet iposos custodes? |


-----PGP PUBLIC KEY BLOCK AVAILABLE-----



 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org




More information about the spug-list mailing list