Python Closing Immediately After Running Script

Python Closing Immediately After Running Script

The problem is that you ask cmd to run your python script as the only task it needs to perform. When python script finishes, the cmd window is closed as the task cmd was performing has exited.

To run the script and keep output on the screen, as @Engineero have rightfully pointed out, you need to:

  1. Run the cmd. Expected result – shell opens, where you can type commands. It shall say something like C:SOMEpath>_, where _ is your cursor.

  2. Navigate to your python script by typing cd C:UsersMeDesktopPython.

  3. Use python interpreter to launch your script by typing python

When you script finishes, you shall see the output on the screen and be able to type next command. I hope that helps.

Add input(hit any key to close) at the end of your program.

that way your script will wait for an input from the user before closing.

Python Closing Immediately After Running Script

Instead of running as


Launch as

python -i

This way the interpreter will remain open after running the script.

Leave a Reply

Your email address will not be published.