Aakash Aakash - 1 year ago 271
Python Question

How to stop command prompt from closing in python?

I am very new to python.. I used the code

x = input(" Hey what is your name " )
print(" Hey, " + x)
input(" press close to exit ")

Because i have looked for this problem on internet and came to know that you have to put some dummy input line at the end to stop the command prompt from getting closed but m still facing the problem.. pls Help

I am using python 3.3

Answer Source

On windows, it's the CMD console that closes, because the Python process exists at the end.

To prevent this, open the console first, then use the command line to run your script. Do this by right-clicking on the folder that contains the script, select Open console here and typing in python scriptname.py in the console.

The alternative is, as you've found out, to postpone the script ending by adding a input() call at the end. This allows the user of the script to choose when the script ends and the console closes.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download