Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know there were some tricks with older versions of windows to accomplish this, but not sure on windows 7.

If I had a piece of software that executes a command with switches resulting in a cmd.exe window opening and closing quickly, how can I reconfigure the command prompt to NOT auto-close once the task is complete.

The trick here is that the command being executed is indeed a batch file, includes a pause statement at the end, but the way the software is trying to execute the command is failing. Since it closes so quickly, we don't know what error is being returned since it closes so quickly.

share|improve this question
Good question, quietly I also wished I known this because sometimes game/software patches come in .BAT files closing after instructions are executed without pausing and displaying executed commands to end user. – Boris_yo May 23 '12 at 15:53
Why not open a command window, cd to that directory and run the batch from there? That would run in the same non-closing cmd window that would stay open when the batch finishes. That might give you some clues to help debug it. – jdh May 23 '12 at 16:00
possible duplicate of How to prevent the command prompt from closing after execution? – slhck May 23 '12 at 16:02
Thanks slhck, you pointing me to that location looks like the closest possibility to achieve what I want is within the registry for batfile/cmdfile. – Tim Winter May 23 '12 at 17:28

Instead of running that .bat file directly from Explorer or whatever other method you use, manually launch cmd.exe(if needed with elevated privileges) and then run you .bat file from there. Then upon completion of its execution you will still see all the output...just like in the good old DOS days. :)

share|improve this answer

In your .bat file, use the pause command. It will prevent your .bat file from closing.

For example, this is my bat file I use to start MySQL service on my PC:

net start MySQL

Note: On Windows 7 I start this .bat file from Administrator's name. To do this click right mouse's button on your .bat file and chose "Start from Administrator's name" from the dropdown menu.

share|improve this answer

You need to use the /k switch when calling.

Useful details here.

share|improve this answer

In .bat scripting, you leave off the "exit" at the end of the script to leave the command window open.

A command window opened by a script always closes itself at the end of the script because it is dependent on the script. Opening the window yourself and running the script does not close the window unless you've specific the "exit" command at the end of the script because the window is not dependent on the script.

It does not appear there is a way to prevent a script-dependent window from being closed once the script ends in Windows 7. However, it is possible error messages would be recorded elsewhere. Does the program have a log file? Or are there entries in the Windows logs?

share|improve this answer

this should work.

share|improve this answer
Please read the question again carefully. Your answer does not answer the original question. "The trick here is that the command being executed is indeed a batch file, includes a pause statement at the end," – DavidPostill Apr 28 at 8:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .