Windows CMD Command Prompt Windows Keep Closing (Or Doesn’t Stay Open)

I was having a hard time with command prompt windows when I created and ran my batch files – they wouldn’t stay open and kept closing before I could see its output.

Then I discovered the PAUSE command – by adding this command to your batch file, you’ll pause the window for as long as you want, keeping it open so that you can read the output it generates!

So if you want your command prompt DOS window to stay open, then use this following piece of code in your batch file:

@ECHO OFF

REM Put your main code here

ECHO Halting operation. Please press enter to continue.
PAUSE>NUL

PAUSE>NUL means that the output of PAUSE will be redirected to the NUL device. This command allows you to replace the default PAUSE message with your own, using an ECHO command before it. In this example, the user will see the message “Halting operation. Please press enter to continue.” Once the user presses enter, the command window will close.

Similar Posts:

Alvin Poh lives in Singapore, and is interested in marketing, techy stuff, and likes to just figure out how the two can work with each other. He can also be found on Google+.

5 comments On Windows CMD Command Prompt Windows Keep Closing (Or Doesn’t Stay Open)

  • I leaned elsewhere and slid in farther.

  • @ECHO OFF

    REM Put your main code here

    ECHO Halting operation. Please press enter to continue.
    PAUSE>NUL

    Hi there, trying to do this, but am a novice.
    1. what is my main code after REM, and how do I create this batch file and when done how do I enter it.
    Easy for you, difficult for me.
    Please help
    Thanks
    Volker

  • your main code is whatever you need executed. you can create it by renaming a text file from “something.txt” to “yourfile.bat”. And then you can use notepad to edit it like a normal text document 🙂

  • please help! my command prompt wont stay open. whenever i try to open it, it comes up but disappears in after few seconds. i cant write programs because of this.

  • Ovie, I think you “cant write programs” for a lot of reasons.

Leave a reply:

Your email address will not be published.


*

Sliding Sidebar