Exporting environment variables 
Author Message
 Exporting environment variables

I'm sure this has come up again and again, and it's not strictly Perl
related, but I can't seem to find an answer....

We have a collection of Perl and other scripts.  To run properly, these scripts
require that certain environment variables be set.  I would like to
write a Perl script to setup the necessary environment variables.
I'd like to be able to run 'setenv.pl' on a console (I'm on Win32),
and have all the environment variables setup for me when the script
exits.  The problem, of course, is that using '$ENV{FOO} = "BAR"' type
stuff is that once the the setenv.pl Perl script exits, we're back in
the parent process and the environment variables set in the child
process (the script) are gone.  Another option is just to use a batch
file, not a Perl script, to set the environment variables.  But, for a
variety of reasons, it would be more maintainable and portable to do
it in Perl.  Any ideas?

Thanks!

--
Steve Molitor



Thu, 27 Feb 2003 03:08:07 GMT  
 Exporting environment variables

Quote:

> I'd like to be able to run 'setenv.pl' on a console (I'm on Win32),
> and have all the environment variables setup for me when the script
> exits.  The problem, of course, is that using '$ENV{FOO} = "BAR"' type
> stuff is that once the the setenv.pl Perl script exits, we're back in
> the parent process and the environment variables set in the child
> process (the script) are gone.  Another option is just to use a batch
> file, not a Perl script, to set the environment variables.  But, for a
> variety of reasons, it would be more maintainable and portable to do
> it in Perl.

Have a batch file that does something like:

perl setenv.pl > setenv.bat  (or .cmd)
call setenv

then have setenv.pl just print "set FOO=BAR" in whatever
"maintainable" way you want.  Not sure what you mean by portable;
where else do you want this to work?



Fri, 28 Feb 2003 04:07:08 GMT  
 Exporting environment variables

Quote:

> I'm sure this has come up again and again, and it's not strictly Perl
> related, but I can't seem to find an answer....

> We have a collection of Perl and other scripts.  To run properly, these scripts
> require that certain environment variables be set.  I would like to
> write a Perl script to setup the necessary environment variables.
> I'd like to be able to run 'setenv.pl' on a console (I'm on Win32),
> and have all the environment variables setup for me when the script
> exits.  The problem, of course, is that using '$ENV{FOO} = "BAR"' type
> stuff is that once the the setenv.pl Perl script exits, we're back in
> the parent process and the environment variables set in the child
> process (the script) are gone.  Another option is just to use a batch
> file, not a Perl script, to set the environment variables.  But, for a
> variety of reasons, it would be more maintainable and portable to do
> it in Perl.  Any ideas?

> Thanks!

Here is one possible solution.

Step 1: Create the script that would set the environment variables for your
scripts.
Step 2: Require that this script be used in all other scripts as part of the
initialization process.

Ensure that all users of the script, include (require) it from the same location if
that is possible.  This will ensure that all users of the script receive any
updates to it automatically as only one copy is maintained.

-=} Randall {=-    Every solution breeds new problems.

Need a tagline?  Visit http://www.taglinesgalore.com/



Fri, 28 Feb 2003 20:19:54 GMT  
 Exporting environment variables


Quote:
> I'm sure this has come up again and again, and it's not strictly Perl
> related, but I can't seem to find an answer....

> We have a collection of Perl and other scripts.  To run properly,
these scripts
> require that certain environment variables be set.  I would like to
> write a Perl script to setup the necessary environment variables.

eval `setenv.pl`

where setenv.pl prints (on stdout):
   export A=B
   export C=D
or whatever

--
John Wiersba

Sent via Deja.com http://www.deja.com/
Before you buy.



Fri, 28 Feb 2003 23:06:11 GMT  
 Exporting environment variables

Quote:

> eval `setenv.pl`

> where setenv.pl prints (on stdout):
>    export A=B
>    export C=D
> or whatever

Now that's slick!  I've received a lot of good ideas here; thanks
everyone.  This is the coolest so far.

We might need to have the same setenv.pl script support a Unix and NT
environment, so we'll just have setenv.pl print 'set A=B' if the OS eq
'NT', else 'export A=B'.  

Thanks!

--
Steve Molitor



Sat, 01 Mar 2003 05:08:58 GMT  
 Exporting environment variables
Howdy

We have a similar setup here... A bunch of scripts
need the same environment at runtime. So, we created
a set of standard files (areaprops, codeprops, userprops)
which are available to everyone. As the environment needs
change, those files can change accordingly.

Then, in a perl package, there's the function:
        get_area_properties()
which checks the standard location if no other
location is supplied for a standard list of 'property'
files, setting these properties as ENV{} vars, or with
another invocation, as $main::AREA{} vars.

So, once the function was written, all the was required
was a
        use OurPackage;
        get_area_properties();
and everybody is happy.

Quote:

> I'm sure this has come up again and again, and it's not strictly Perl
> related, but I can't seem to find an answer....

> We have a collection of Perl and other scripts.  To run properly, these scripts
> require that certain environment variables be set.  I would like to
> write a Perl script to setup the necessary environment variables.
> I'd like to be able to run 'setenv.pl' on a console (I'm on Win32),
> and have all the environment variables setup for me when the script
> exits.  The problem, of course, is that using '$ENV{FOO} = "BAR"' type
> stuff is that once the the setenv.pl Perl script exits, we're back in
> the parent process and the environment variables set in the child
> process (the script) are gone.  Another option is just to use a batch
> file, not a Perl script, to set the environment variables.  But, for a
> variety of reasons, it would be more maintainable and portable to do
> it in Perl.  Any ideas?

> Thanks!

> --
> Steve Molitor




Sun, 02 Mar 2003 03:00:00 GMT  
 Exporting environment variables

Quote:


> > eval `setenv.pl`

> > where setenv.pl prints (on stdout):
> >    export A=B
> >    export C=D
> > or whatever

> Now that's slick!  I've received a lot of good ideas here; thanks
> everyone.  This is the coolest so far.

> We might need to have the same setenv.pl script support a Unix and NT
> environment, so we'll just have setenv.pl print 'set A=B' if the OS eq
> 'NT', else 'export A=B'.

On NT, change 'export' to 'set' and wrap it in the following instead of
an 'eval':

        for /f "delims=`" %a in ('perl setenv.pl') do %a

Remember to double up the '%'s  inside a .BAT.

--
Thomas Pfau


http://www.eclipse.net/~pfau/



Mon, 03 Mar 2003 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. TUTIL32 and DLL index value help?

2. Nuno Ferreira

3. ACCESS + DELPHI or VB ??

4. A problem with Indexes in Paradox tables

5. Validators and Exceptions

6. Exporting environment variables

7. Exporting environment variables

8. Exporting environment variables in CGI-script

9. Export environment variable to parent

10. Exporting environment variables to parent shell

11. How do I export environment variables?

12. Exporting environment variables in CGI-script

 

 
Powered by phpBB® Forum Software