On Thu, Jan 14, 2016 at 7:03 PM, Andrew Ongko <andrew.on...@gmail.com> wrote:
> At least, this way, the cmd doesn't close by itself.

This phrasing may perpetuate a common misconception that the Windows
console is (or is created by) cmd.exe. The cmd.exe shell is just
another console client process, no different from python.exe or
powershell.exe in that respect.

When you run a .py script from a GUI application such as explorer.exe,
Windows creates a console window for python.exe, since it doesn't
inherit one. In Windows 7+, the console window is hosted by an
instance of conhost.exe (i.e. this process has the window procedure
and message loop). Older versions host it in csrss.exe. When
python.exe exits, there's no longer a process attached to the console,
so the console host process also exits. To keep the console window
alive, you can either start python.exe from an existing console
process (e.g. cmd, powershell, or even python), or just before exiting
create a new console process that attaches to the console.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to