http://qs321.pair.com?node_id=658278


in reply to Changing parent process environment variable

It is not possible for a child process to directly alter the parent's environment block without using some shared memory magic - and that is true whatever the language used, compiled or not.

The environment block is set at process creation time and by default is a copy of the parent's. There is no concept of a "global" environment. All this is true on Windows and UNIX.

However on Windows, environment variables are also stored in the Registry, either in HKEY_CURRENT_USER\Environment (user variables) or HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment (system variables). So you could use one of the (several) Win32 Perl modules to change the registry.

Now the tricky bit: for the parent to pick-up the change you should send a WM_SETTINGCHANGE message. I don't know how to do that from Perl, but there probably is a way. Look at the Win32:: namespace modules.

There are easier ways to pass a text string between programs ;-)