Mobile Number Tracker
Trace Mobile Number Earn Money Online

Stop Command Prompt Window from Closing

A typical cmd Command Prompt Window.
Samyak Lalit | August 1, 2012 (Last update: September 23, 2017)

Samyak Lalit is an Indian author and disability rights activist. He is the principal author and founder of projects like TechWelkin, WeCapable, Viklangta, Kavita Kosh among many others.

Although times of MS DOS operating system are more or less gone, but still sometimes we still create batch files (.bat files) to write small programs. Batch files are a series of commands that are executed in sequence one after the other.

People generally write batches of DOS commands or shell commands. When you execute a DOS (Windows) batch file by double clicking the .bat file –the command prompt windows pops up, execute commands quickly and then disappears. If your batch file is short and commands don’t take much time to execute, you may not even properly see the cmd window on screen! It all happens so quickly. This, usually black colored, cmd window will not stay to show how your batch file executed.

Is there is a way prevent cmd window from automatically closing? Yes! There is!

A typical cmd Command Prompt Window.

A typical cmd Command Prompt Window.

If you want the command prompt cmd widnow to stay open after executing the last command in batch file –you should write cmd /k command at the end of your batch file. This command will prevent the command prompt window from closing and you’ll get the prompt back for giving more commands in the cmd window.

A typical use case of this scenario is when you want a command prompt window be ready after auto-execution of certain commands that you always give (For example, changing drive or directory).

I hope this was a useful tip for you. Please let me know if you have any questions about this topic. I will be happy to try and answer it for you. Thank you for using TechWelkin.


3 responses to “Stop Command Prompt Window from Closing”

  1. mina says:

    It’s Worked, Thank you a LOT

  2. Mike says:

    thanks, that worked for me

    net localgroup administrators
    net localgroup “Remote Desktop Users”
    cmd /k

  3. DFG says:

    Windows 7: that doesn’t work, the bat file keeps closing.

Leave a Reply

Your email address will not be published. Required fields are marked *