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:
-
Run the
cmd
. Expected result – shell opens, where you can type commands. It shall say something likeC:SOMEpath>_
, where_
is your cursor. -
Navigate to your python script by typing
cd C:UsersMeDesktopPython
. -
Use python interpreter to launch your script by typing
python myfile.py
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
cmd C:UsersMeDesktopPythonmyfile.py
Launch as
python -i C:UsersMeDesktopPythonmyfile.py
This way the interpreter will remain open after running the script.