Prevent the command prompt closing automatically

October 2017

If you suddenly see the automatic closure of your command prompt then revoke a command from the Start point and select the Run option in your operating system. Then open a command prompt window by keying CMD at the Start and the Run option. Now enter a command in the open window. By typing cmd /k, the /k option makes the shell stay open after command execution. Sometimes it is possible to change the features of the command prompt's action into the registry, because causing it to remain for input prior to closing is impractical. Thee "press any key to continue" prompts are programmed from the programs/scripts themselves, not CMD. You may consider rewriting every program to add that prompt, to get your desired results.

Sometimes, you will find that the command prompt window closes automatically when you don't want it to.

To address this problem:
  • Press Windows key + R to open the Run window
  • Launch the command prompt by typing:
     cmd /K
    • Adding / K after the command keeps the window open
    • You can then close the window manually when you no longer need it to be open .

Try, for example:
cmd /k tracert


Published by jak58. Latest update on February 19, 2012 at 07:30 PM by Paul Berentzen.
This document, titled "Prevent the command prompt closing automatically," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (