This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: py launcher on windows opens new terminal window when parsing python script with shebang
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.10
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: chrias, eryksun, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2022-03-30 16:28 by chrias, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (6)
msg416380 - (view) Author: Christian Ascia (chrias) Date: 2022-03-30 16:28
Hi, as the title describes, i noticed this unfornutate behavior preventing me to run directly python scripts in terminal without using the py command. I searched in the documentation but i couldn't find flags to prevent py launcher from opening a new window.
msg416381 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2022-03-30 16:47
Are you saying this happens when you run "py.exe"? Or only when you run "" (without the py.exe)?
msg416382 - (view) Author: Christian Ascia (chrias) Date: 2022-03-30 16:56
It happens when i run "".
I checked all terminal emulators on my system, it happens on PowerShell 7, in all Windows Terminal profiles (including cmd profile), in integrated terminals on vscode but not in cmd.
msg416383 - (view) Author: Paul Moore (paul.moore) * (Python committer) Date: 2022-03-30 16:58
This is Windows (shell) behaviour. To avoid this, you need to add the .py extension to the PATHEXT environment variable.
msg416384 - (view) Author: Christian Ascia (chrias) Date: 2022-03-30 17:01
Thanks, it works now!
msg416512 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2022-04-01 19:33
> This is Windows (shell) behaviour. To avoid this, you need to 
> add the .py extension to the PATHEXT environment variable.

PowerShell reuses the current console session only if .PY is set in PATHEXT. Otherwise Python gets executed with a flag that tells the system to allocate a new console session.

For CMD, PATHEXT only affects the file search, not how the file is executed. If the internal START command isn't used, CMD reuses the current console session. The START command defaults to making the system allocate a new console, unless the /B option is used.
Date User Action Args
2022-04-11 14:59:57adminsetgithub: 91326
2022-04-01 19:33:47eryksunsetnosy: + eryksun
messages: + msg416512
2022-03-30 17:01:29chriassetstatus: open -> closed
resolution: fixed
messages: + msg416384

stage: resolved
2022-03-30 16:58:30paul.mooresetmessages: + msg416383
2022-03-30 16:56:41chriassetmessages: + msg416382
2022-03-30 16:47:05steve.dowersetmessages: + msg416381
2022-03-30 16:28:35chriascreate