user1586464
user1586464

Reputation: 257

how to make my console in python not to close?

I'm making a application in python from Windows. When I run it in the console, it stops, shows an error, and closes. I can't see the error becase its too fast, and I can't read it. I'm editing the code with IDLE (the program that came with python when I instaled it), and when I run it with the python shell, there are no errors. I would run it from IDLE, but when I use the console, it has more features.

I don't know why this is happening. I need your help.

Upvotes: 1

Views: 9417

Answers (3)

user4261180
user4261180

Reputation: 171

Create a text file in the program directory i.e. wherever your script is located. Change the extension to .bat for example text.bat. Then edit the text file and write:

python main.exe
pause

Now you can run the program without typing into the command console by double clicking the bat file, and the console window will not close.

Upvotes: 1

Brian Carpio
Brian Carpio

Reputation: 491

Run the program from an already-open terminal. Open a command prompt and type:

python myscript.py

For that to work you need the python executable in your path. Just check on how to edit environment variables on windows, and add C:\PYTHON26 (or whatever directory you installed python to).When the program ends, it'll drop you back to the CMD windows prompt instead of closing the window.Add code to wait at the end of your script. Adding ...

raw_input()

... at the end of the script makes it wait for the ENTER key. That method is annoying because you have to modify the script, and have to remember removing it when you're done.

Upvotes: 2

Greg Hewgill
Greg Hewgill

Reputation: 992707

Run your program from a Windows command prompt. That will not automatically close when the program finishes.

If you run your program by double-clicking on the .py file icon, then Windows will close the window when your program finishes (whether it was successful or not).

Upvotes: 1

Related Questions