
Is there is a way prevent cmd window from automatically closing? Yes! There is! A typical cmd Command Prompt Window. This, usually black colored, cmd window will not stay to show how your batch file executed. 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.

bat file –the command prompt windows pops up, execute commands quickly and then disappears. When you execute a DOS (Windows) batch file by double clicking the. People generally write batches of DOS commands or shell commands. Batch files are a series of commands that are executed in sequence one after the other. C:\WINDOWS\system32\cmd.exe /K įrom : /K command - Executes the specified command and continues running.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. When the script exits, the window will not close automatically, so you can see any errorsĪlso, as Chris Thornhill suggested, on Windows, you can create a shortcut to your script, and in it’s Properties prefix the target with. The easiest way would be to use IDLE, launch IDLE, open the script and click the run button ( F5 or Ctrl+F5 I think). On Linux/Mac OS X it’s a bit easier, you just run cd /home/your/script/ then python myscriptname.py (If you installed Python into C:\Python\) On Windows, go to Start > Run, enter cmd and enter. If you don’t have a main() function, you would use put the import statement in the try: block: try:Ī better solution, one that requires no extra wrapper-scripts, is to run the script either from IDLE, or the command line. (Note that raw_input() has been replaced by input() in Python 3) and the file is named “myscriptname.py” (obviously that can be changed), the following will work from myscriptname import main as myscript_main This script would catch all exceptions, and print a traceback (then wait for user input before ending)Īssuming your code is structured using the if _name_ = "_main_": main() idiom. You could have a second script, which imports/runs your main code.
