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

Share on facebook
Facebook
Share on google
Google+
Share on twitter
Twitter
Share on linkedin
LinkedIn

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:

More to explorer

how i started being a minimalist

How I Started Being A Minimalist

Once, I thought that all that mattered in life were the things that you possessed. Things like your car, house, watch, clothes.

5 Responses

  1. @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

  2. 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 🙂

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

Leave a Reply

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