7

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).

2 Answers 2

5

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.

0

Well in a windows console, just type cmd and hit enter. This technically puts you in a new session inside your other session, but it will have the new env variables. What it won't have is session information from the outer session. So any env variables or command history, that sort of thing.

1
  • Does not work for me. Scenario: 1) while being in the Cygwin shell (bash) I've added new directory my_dir to PATH env. variable, 2) type cmd => Command Prompt is opened, 3) type my_app (which is in the my_dir), 4) my_app: command not found. Note: the same behavior if instead of Cygwin shell (bash) the Command Prompt (cmd) is initially used. Solution: need to manually close-open the shell (bash / cmd) to refresh the env. variables. Which is tiresome. Looking for a solution.
    – pmor
    Jan 17, 2021 at 18:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .