How do I export environment variables? 
Author Message
 How do I export environment variables?

At the end of a config script I wrote I would like to export my
environment variables.  I want the perl script to leave the environment
of the shell it's running in different than when it started. Then other
commands executed from the shell that executed the perl script can use
the modified environment variables.

-Bill

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
: William V. Wishon     : There is so much good in the worst of us, :
: Release Engineer      : So much bad in the best of us,            :
: Adobe Systems Inc.    : That it scarcely behooves any of us       :

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::



Fri, 28 Jul 2000 03:00:00 GMT  
 How do I export environment variables?



Quote:
> At the end of a config script I wrote I would like to export my
> environment variables.  I want the perl script to leave the environment
> of the shell it's running in different than when it started. Then other
> commands executed from the shell that executed the perl script can use
> the modified environment variables.

The short answer is: You can't.

This question is answered in section 8 of the FAQ.

perldoc perlfaq8
/I {changed directory, modified my environment} in a perl
     script.  How come the change disappeared when I exited the
     script?  How do I get my changes to be visible?

Martien
--
Martien Verbruggen                  |
Webmaster www.tradingpost.com.au    | If it isn't broken, it doesn't have
Commercial Dynamics Pty. Ltd.       | enough features yet.
NSW, Australia                      |



Fri, 28 Jul 2000 03:00:00 GMT  
 How do I export environment variables?

 [courtesy cc of this posting sent to cited author via email]


:At the end of a config script I wrote I would like to export my
:environment variables.  I want the perl script to leave the environment
:of the shell it's running in different than when it started. Then other
:commands executed from the shell that executed the perl script can use
:the modified environment variables.

This is a FAQ.

    $ man perlfaq8
       I {changed directory, modified my environment} in a perl script.
       How come the change disappeared when I exited the script?  How do
       I get my changes to be visible?

The answer is, you don't.  That would be {*filter*}uous to{*filter*}around with
your parent process that way.  

Hm... my new killfile isn't detecting you're posting from Windows.
Darn it.

--tom
--

    It's documented in The Book, somewhere...



Sat, 29 Jul 2000 03:00:00 GMT  
 How do I export environment variables?

Quote:

>At the end of a config script I wrote I would like to export my
>environment variables.  I want the perl script to leave the environment
>of the shell it's running in different than when it started. Then other
>commands executed from the shell that executed the perl script can use
>the modified environment variables.

>-Bill

If you're talking about on Windows then see the thread "How can I set
enviroment variables on Win32?" of 14 Jan 98.

I don't know about on unix, or other platforms, but this was my response
(you'll probably be interested in the 3rd suggestion of altering the .bat
file...):



Quote:
>If you want to set the env var within your script and for any programs you call
>from within your script (e.g. by doing a system()) - just add/set the env var
>in %ENV, e.g.
>$ENV{new_var} = "value";

>If you want to set the env var in *future* command prompts then you can set the
>env var in the registry (using Win32::Registry). The env vars are stored in:
>\\HKEY_CURRENT_USER\\Environment

>Some example code to set an env var in the registry is:

>use Win32::Registry;
>my $regkey;
>$HKEY_CURRENT_USER->Open('Environment', $regkey) || die;
>$regkey->SetValueEx("env_var_name", &NULL, &REG_SZ, "value");
>$regkey->Close();

>You get my drift. This only works on NT as 95 doesn't store env vars in the
>registry. For 95 you have to alter autoexec.bat.

>If you want to alter the env vars within the shell/program that called your
>perl script, this is a different matter. The only way I've found to do this is
>to write out a temporary file from within your perl script, and then execute
>this as a batch file, e.g.



>set CMD=%0
>set ARGS=
>:loop
>if .%1==. goto endloop
>set ARGS=%ARGS% %1
>shift
>goto loop
>:endloop
>perl.exe -S %CMD% %ARGS%
>if exist %temp%\shellenvs.bat call %temp%\shellenvs.bat
>if exist %temp%\shellenvs.bat del %temp%\shellenvs.bat
>goto endofperl

># this is where the perl starts!!!
>my $tempfile = $ENV{TEMP} . "\\shellenvs.bat";
>open(BATFILE, "> $tempfile") || die;
>print BATFILE "set THISVAR=VALUE\n";
>close(BATFILE);

>__END__
>:endofperl

>Save all of the above in a .bat file and it should work. Note the couple of
>lines at the top of the .bat bit that calls the shellenvs.bat - this is the
>script your perl script will generate and it's in here that you issue the shell
>"set" commands to set the env vars.

>All of the above methods work and I use them in a number of scripts we use
>daily.

Hope that helps,
Jamie
___________________________________________________________________________

Oracle C++ Object Layer Generator Team
______________________________________________________  __  __ _  __ .   __
Opinions expressed here are my own and not those of... (__)|-</-\(__ |__ -_


Sat, 29 Jul 2000 03:00:00 GMT  
 How do I export environment variables?

[posted & mailed]

        >snip<
: Hm... my new killfile isn't detecting you're posting from Windows.
: Darn it.

        I'm surprised Tom, how could it miss the "X-Mailer: Mozilla 4.01 [en] (WinNT;
        U)" header line?  Personally, I find the attempted use of Netscape as a
        newsreader even worse then the attempted use of WinNT as an OS. :-)

        But the combination....  *sutters*

--
-Zenin



Mon, 31 Jul 2000 03:00:00 GMT  
 How do I export environment variables?


Quote:

>        I'm surprised Tom, how could it miss the "X-Mailer: Mozilla 4.01
[en] (WinNT;
>        U)" header line?  Personally,

<etc>

Now, I have a theory about this (admiitedly crap) newsreader I'm using....

/J\



Mon, 31 Jul 2000 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. exporting perl variable into and environment variable

2. Exporting environment variables

3. Exporting environment variables

4. Exporting environment variables

5. Exporting environment variables in CGI-script

6. Export environment variable to parent

7. Exporting environment variables to parent shell

8. How to export an environment variable ?

9. Exporting environment variables in CGI-script

10. How to Export Environment variables ?

11. Export of Environment Variables

12. Exporting environment variables

 

 
Powered by phpBB® Forum Software