Windows – How to update cygwin shell environment variables set in System Properties window

cygwin;environment-variablespathterminalwindows

Suppose I go into the System Properties window and add an environment variable to the Path. If I have a terminal window open, it will be unaware of the change, so I close it and open another one.

Is there a way to have it reload the Path information from the command line? I'd particularly like to know how I can do it with my Cygwin shell, but I'd be happy to know how to handle either case (Cygwin or native terminal).

Best Answer

There is not built-in method for changes to be propagated to child processes automatically, processes can be setup to listen for a particular message, and update, but for that requires special handling within the application.

Propgation of the environment to some applications is the exception rather then the rule. The normal behavior is that when process is created it gets a copy of the environment from the parent process. Changes with to the environment within that process do not propagate back to the parent. After a process has been created any further changes in the environment of the parent do not get propagated to the child.

On Windows the environment the system variables that you set through that interface are stored in the registry, so you could theoretically write a script in cygwin that would re-read the registry and output the current variables, and then use that to update the environment in the current shell.

From the kb http://support.microsoft.com/kb/104011

However, note that modifications to the environment variables do not result in immediate change. For example, if you start another Command Prompt after making the changes, the environment variables will reflect the previous (not the current) values. The changes do not take effect until you log off and then log back on.

To effect these changes without having to log off, broadcast a WM_SETTINGCHANGE message to all windows in the system, so that any interested applications (such as Windows Explorer, Program Manager, Task Manager, Control Panel, and so forth) can perform an update.

Related Question