I wish to create a bat file to create some basic task. When i run this it closes the window. I'm guessing it errors. How can i stop the bat closing the window so i can view the error.


echo cd /d d:
echo sencha create jsb -a http://my.local/ext/cutter/app/index.html -p app.jsb3
echo sencha build app.jsb3 -d .
  • does it work? i mean, does it do what you wish it to do? is the only problem the fact that it closes?
    – acolyte
    Jun 14, 2012 at 17:14

4 Answers 4


Batch scripts will close the window itself after running it is not an indication of an error, if you put the word pause at the end of the script the script will stop and wait for you to press a key before proceeding


Two options:

  1. send output to a file (command > c:\output.log)

  2. Set a delay. In newer versions, it can be done with timeout \t xxx where xxx is the amount of seconds. In older versions, you can produce an effective delay with things like

    PING -n 6

where each ping takes about one second... but hey, you don't need precission, right? :)

Both approaches avoid being frenzy on the pause button

  • +1 redirecting output
    – Nixphoe
    Jun 20, 2012 at 2:21

The answer by Chris is correct. However if it were actually an error, the pause would not stop the cmd shell from just exiting. Here's how I troubleshoot this simply without redirecting output (and having to keep opening the output log file):

Run cmd.exe. Then within the command window, run 'cmd<enter>' a couple more times. This executes cmd.exe as a child of cmd.exe but within the same command window.

Now call the .bat / .cmd from within the command window, e.g. C:\Temp\mybat.bat - if it errors it will exit the cmd.exe it was running in and display the error (and any other output) in the window but return processing to the parent cmd.exe process within the same command window. As there is a parent process the batch window will not just close on error.


Run it from the commandline (cmd) and it will show you the output and not close when finished. The reason it is closing is because you are simply echoing (printing) stuff to the terminal. It isn't actually DOING anything. Take out all those echoes.

C:\>echo /?
Displays messages, or turns command-echoing on or off.

  ECHO [message]

Type ECHO without parameters to display the current echo setting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.