When must I restart Powershell or cmd prompt to access up-to-date machine state?












0















Can anyone explain when/why it is necessary to restart Powershell and/or cmd prompt (if they behave differently with respect to this question)?



For example, in order to work with the most up-to-date machine state, must I restart Powershell after:



1) Editing system environment variable such as Path



2) Installing things such as npm modules



3) Editing a file such as a .txt or a file within a VSCode project



Thanks in advance!










share|improve this question



























    0















    Can anyone explain when/why it is necessary to restart Powershell and/or cmd prompt (if they behave differently with respect to this question)?



    For example, in order to work with the most up-to-date machine state, must I restart Powershell after:



    1) Editing system environment variable such as Path



    2) Installing things such as npm modules



    3) Editing a file such as a .txt or a file within a VSCode project



    Thanks in advance!










    share|improve this question

























      0












      0








      0








      Can anyone explain when/why it is necessary to restart Powershell and/or cmd prompt (if they behave differently with respect to this question)?



      For example, in order to work with the most up-to-date machine state, must I restart Powershell after:



      1) Editing system environment variable such as Path



      2) Installing things such as npm modules



      3) Editing a file such as a .txt or a file within a VSCode project



      Thanks in advance!










      share|improve this question














      Can anyone explain when/why it is necessary to restart Powershell and/or cmd prompt (if they behave differently with respect to this question)?



      For example, in order to work with the most up-to-date machine state, must I restart Powershell after:



      1) Editing system environment variable such as Path



      2) Installing things such as npm modules



      3) Editing a file such as a .txt or a file within a VSCode project



      Thanks in advance!







      powershell cmd.exe






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 24 at 16:27









      dillon.harlessdillon.harless

      83




      83






















          2 Answers
          2






          active

          oldest

          votes


















          1














          Generally you only need reload your shell when your environment changes - its generally quick and easy and basically guaranteed to work. But it can be annoying, and depending on what your doing not strictly necessary.



          Both CMD and Powershell read the user/system environment variables at startup and apply them to the current shell. When you make changes to values like PATH from within this shell, your just updating the default values used by any new shells (CMD or POSH), and generally not changing the current shells environment.



          Things like the PATH can be changed within the current shell, but its done differently in CMD vs POSH. Here is a simple demo that shows this in action with command prompt.



          Open a CMD prompt, and run these to commands to setup the demo:



          C:>mkdir c:pathtest
          C:>echo @echo hello > c:pathtestsayhello.cmd


          if you switch to c:pathtest and execute sayhello, it should work as expected and print "hello" to the screen:



          C:>cd c:pathtest
          C:pathtest>sayhello
          hello


          Now, change directory back to the root, and run sayhello again and you get a command not recognised error:



          C:pathtest>cd ..
          C:>sayhello
          'sayhello' is not recognized as an internal or external command,
          operable program or batch file.


          Now the magic, the below updates the PATH of your current shell(only) to include c:pathtest, and allows your to run sayhello from anywhere.



          C:>SET PATH=%PATH%;c:pathtest
          C:>sayhello
          hello


          Close the CMD prompt, and open a new one, and the PATH statement has reverted to its original value and sayhello will no longer work. (you can delete c:pathtest now too).



          The same applies to Powershell - you can manipulate the builtin $env variable to alter the PATH etc for just the current session.



          So, back to your original questions:




          For example, in order to work with the most up-to-date machine state,
          must I restart Powershell after:



          1) Editing system environment variable such as Path



          2) Installing things such as npm modules



          3) Editing a file such as a .txt or a file within a VSCode project





          1. If your environment variables change (like installing something that modifies the PATH) restating your shell is the easiest fix - but as described above, you can work around this if you know what change was made and manually apply it to your current shell.


          2. npm modules sit on the filesystem so unless they are modifying the PATH or such you shouldnt need to reload the shell to see changes.


          3. As above, when you hit save in your editor, that data is written to disk. When you execute POSH/CMD its read from the disk by the interpreter at runtime.







          share|improve this answer
























          • Great answer. Cheers.

            – dillon.harless
            Jan 24 at 19:09



















          1














          A process that listens for the WM_SETTINGCHANGE window message will be capable of updating its current environment variables without restarting.



          I think ignoring WM_SETTINGCHANGE from Powershell and CMD is intentional to ensure that environment variables can't be changed during the execution of a script.



          More info:
          Environment Variables
          Restarting Windows to refresh Local System environment variables






          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1397992%2fwhen-must-i-restart-powershell-or-cmd-prompt-to-access-up-to-date-machine-state%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Generally you only need reload your shell when your environment changes - its generally quick and easy and basically guaranteed to work. But it can be annoying, and depending on what your doing not strictly necessary.



            Both CMD and Powershell read the user/system environment variables at startup and apply them to the current shell. When you make changes to values like PATH from within this shell, your just updating the default values used by any new shells (CMD or POSH), and generally not changing the current shells environment.



            Things like the PATH can be changed within the current shell, but its done differently in CMD vs POSH. Here is a simple demo that shows this in action with command prompt.



            Open a CMD prompt, and run these to commands to setup the demo:



            C:>mkdir c:pathtest
            C:>echo @echo hello > c:pathtestsayhello.cmd


            if you switch to c:pathtest and execute sayhello, it should work as expected and print "hello" to the screen:



            C:>cd c:pathtest
            C:pathtest>sayhello
            hello


            Now, change directory back to the root, and run sayhello again and you get a command not recognised error:



            C:pathtest>cd ..
            C:>sayhello
            'sayhello' is not recognized as an internal or external command,
            operable program or batch file.


            Now the magic, the below updates the PATH of your current shell(only) to include c:pathtest, and allows your to run sayhello from anywhere.



            C:>SET PATH=%PATH%;c:pathtest
            C:>sayhello
            hello


            Close the CMD prompt, and open a new one, and the PATH statement has reverted to its original value and sayhello will no longer work. (you can delete c:pathtest now too).



            The same applies to Powershell - you can manipulate the builtin $env variable to alter the PATH etc for just the current session.



            So, back to your original questions:




            For example, in order to work with the most up-to-date machine state,
            must I restart Powershell after:



            1) Editing system environment variable such as Path



            2) Installing things such as npm modules



            3) Editing a file such as a .txt or a file within a VSCode project





            1. If your environment variables change (like installing something that modifies the PATH) restating your shell is the easiest fix - but as described above, you can work around this if you know what change was made and manually apply it to your current shell.


            2. npm modules sit on the filesystem so unless they are modifying the PATH or such you shouldnt need to reload the shell to see changes.


            3. As above, when you hit save in your editor, that data is written to disk. When you execute POSH/CMD its read from the disk by the interpreter at runtime.







            share|improve this answer
























            • Great answer. Cheers.

              – dillon.harless
              Jan 24 at 19:09
















            1














            Generally you only need reload your shell when your environment changes - its generally quick and easy and basically guaranteed to work. But it can be annoying, and depending on what your doing not strictly necessary.



            Both CMD and Powershell read the user/system environment variables at startup and apply them to the current shell. When you make changes to values like PATH from within this shell, your just updating the default values used by any new shells (CMD or POSH), and generally not changing the current shells environment.



            Things like the PATH can be changed within the current shell, but its done differently in CMD vs POSH. Here is a simple demo that shows this in action with command prompt.



            Open a CMD prompt, and run these to commands to setup the demo:



            C:>mkdir c:pathtest
            C:>echo @echo hello > c:pathtestsayhello.cmd


            if you switch to c:pathtest and execute sayhello, it should work as expected and print "hello" to the screen:



            C:>cd c:pathtest
            C:pathtest>sayhello
            hello


            Now, change directory back to the root, and run sayhello again and you get a command not recognised error:



            C:pathtest>cd ..
            C:>sayhello
            'sayhello' is not recognized as an internal or external command,
            operable program or batch file.


            Now the magic, the below updates the PATH of your current shell(only) to include c:pathtest, and allows your to run sayhello from anywhere.



            C:>SET PATH=%PATH%;c:pathtest
            C:>sayhello
            hello


            Close the CMD prompt, and open a new one, and the PATH statement has reverted to its original value and sayhello will no longer work. (you can delete c:pathtest now too).



            The same applies to Powershell - you can manipulate the builtin $env variable to alter the PATH etc for just the current session.



            So, back to your original questions:




            For example, in order to work with the most up-to-date machine state,
            must I restart Powershell after:



            1) Editing system environment variable such as Path



            2) Installing things such as npm modules



            3) Editing a file such as a .txt or a file within a VSCode project





            1. If your environment variables change (like installing something that modifies the PATH) restating your shell is the easiest fix - but as described above, you can work around this if you know what change was made and manually apply it to your current shell.


            2. npm modules sit on the filesystem so unless they are modifying the PATH or such you shouldnt need to reload the shell to see changes.


            3. As above, when you hit save in your editor, that data is written to disk. When you execute POSH/CMD its read from the disk by the interpreter at runtime.







            share|improve this answer
























            • Great answer. Cheers.

              – dillon.harless
              Jan 24 at 19:09














            1












            1








            1







            Generally you only need reload your shell when your environment changes - its generally quick and easy and basically guaranteed to work. But it can be annoying, and depending on what your doing not strictly necessary.



            Both CMD and Powershell read the user/system environment variables at startup and apply them to the current shell. When you make changes to values like PATH from within this shell, your just updating the default values used by any new shells (CMD or POSH), and generally not changing the current shells environment.



            Things like the PATH can be changed within the current shell, but its done differently in CMD vs POSH. Here is a simple demo that shows this in action with command prompt.



            Open a CMD prompt, and run these to commands to setup the demo:



            C:>mkdir c:pathtest
            C:>echo @echo hello > c:pathtestsayhello.cmd


            if you switch to c:pathtest and execute sayhello, it should work as expected and print "hello" to the screen:



            C:>cd c:pathtest
            C:pathtest>sayhello
            hello


            Now, change directory back to the root, and run sayhello again and you get a command not recognised error:



            C:pathtest>cd ..
            C:>sayhello
            'sayhello' is not recognized as an internal or external command,
            operable program or batch file.


            Now the magic, the below updates the PATH of your current shell(only) to include c:pathtest, and allows your to run sayhello from anywhere.



            C:>SET PATH=%PATH%;c:pathtest
            C:>sayhello
            hello


            Close the CMD prompt, and open a new one, and the PATH statement has reverted to its original value and sayhello will no longer work. (you can delete c:pathtest now too).



            The same applies to Powershell - you can manipulate the builtin $env variable to alter the PATH etc for just the current session.



            So, back to your original questions:




            For example, in order to work with the most up-to-date machine state,
            must I restart Powershell after:



            1) Editing system environment variable such as Path



            2) Installing things such as npm modules



            3) Editing a file such as a .txt or a file within a VSCode project





            1. If your environment variables change (like installing something that modifies the PATH) restating your shell is the easiest fix - but as described above, you can work around this if you know what change was made and manually apply it to your current shell.


            2. npm modules sit on the filesystem so unless they are modifying the PATH or such you shouldnt need to reload the shell to see changes.


            3. As above, when you hit save in your editor, that data is written to disk. When you execute POSH/CMD its read from the disk by the interpreter at runtime.







            share|improve this answer













            Generally you only need reload your shell when your environment changes - its generally quick and easy and basically guaranteed to work. But it can be annoying, and depending on what your doing not strictly necessary.



            Both CMD and Powershell read the user/system environment variables at startup and apply them to the current shell. When you make changes to values like PATH from within this shell, your just updating the default values used by any new shells (CMD or POSH), and generally not changing the current shells environment.



            Things like the PATH can be changed within the current shell, but its done differently in CMD vs POSH. Here is a simple demo that shows this in action with command prompt.



            Open a CMD prompt, and run these to commands to setup the demo:



            C:>mkdir c:pathtest
            C:>echo @echo hello > c:pathtestsayhello.cmd


            if you switch to c:pathtest and execute sayhello, it should work as expected and print "hello" to the screen:



            C:>cd c:pathtest
            C:pathtest>sayhello
            hello


            Now, change directory back to the root, and run sayhello again and you get a command not recognised error:



            C:pathtest>cd ..
            C:>sayhello
            'sayhello' is not recognized as an internal or external command,
            operable program or batch file.


            Now the magic, the below updates the PATH of your current shell(only) to include c:pathtest, and allows your to run sayhello from anywhere.



            C:>SET PATH=%PATH%;c:pathtest
            C:>sayhello
            hello


            Close the CMD prompt, and open a new one, and the PATH statement has reverted to its original value and sayhello will no longer work. (you can delete c:pathtest now too).



            The same applies to Powershell - you can manipulate the builtin $env variable to alter the PATH etc for just the current session.



            So, back to your original questions:




            For example, in order to work with the most up-to-date machine state,
            must I restart Powershell after:



            1) Editing system environment variable such as Path



            2) Installing things such as npm modules



            3) Editing a file such as a .txt or a file within a VSCode project





            1. If your environment variables change (like installing something that modifies the PATH) restating your shell is the easiest fix - but as described above, you can work around this if you know what change was made and manually apply it to your current shell.


            2. npm modules sit on the filesystem so unless they are modifying the PATH or such you shouldnt need to reload the shell to see changes.


            3. As above, when you hit save in your editor, that data is written to disk. When you execute POSH/CMD its read from the disk by the interpreter at runtime.








            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 24 at 18:54









            MisterSmithMisterSmith

            2645




            2645













            • Great answer. Cheers.

              – dillon.harless
              Jan 24 at 19:09



















            • Great answer. Cheers.

              – dillon.harless
              Jan 24 at 19:09

















            Great answer. Cheers.

            – dillon.harless
            Jan 24 at 19:09





            Great answer. Cheers.

            – dillon.harless
            Jan 24 at 19:09













            1














            A process that listens for the WM_SETTINGCHANGE window message will be capable of updating its current environment variables without restarting.



            I think ignoring WM_SETTINGCHANGE from Powershell and CMD is intentional to ensure that environment variables can't be changed during the execution of a script.



            More info:
            Environment Variables
            Restarting Windows to refresh Local System environment variables






            share|improve this answer




























              1














              A process that listens for the WM_SETTINGCHANGE window message will be capable of updating its current environment variables without restarting.



              I think ignoring WM_SETTINGCHANGE from Powershell and CMD is intentional to ensure that environment variables can't be changed during the execution of a script.



              More info:
              Environment Variables
              Restarting Windows to refresh Local System environment variables






              share|improve this answer


























                1












                1








                1







                A process that listens for the WM_SETTINGCHANGE window message will be capable of updating its current environment variables without restarting.



                I think ignoring WM_SETTINGCHANGE from Powershell and CMD is intentional to ensure that environment variables can't be changed during the execution of a script.



                More info:
                Environment Variables
                Restarting Windows to refresh Local System environment variables






                share|improve this answer













                A process that listens for the WM_SETTINGCHANGE window message will be capable of updating its current environment variables without restarting.



                I think ignoring WM_SETTINGCHANGE from Powershell and CMD is intentional to ensure that environment variables can't be changed during the execution of a script.



                More info:
                Environment Variables
                Restarting Windows to refresh Local System environment variables







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 24 at 16:58









                RomenRomen

                112




                112






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Super User!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1397992%2fwhen-must-i-restart-powershell-or-cmd-prompt-to-access-up-to-date-machine-state%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                    Mangá

                    Eduardo VII do Reino Unido