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.

classification
Title: Windows py launcher fails to handle a quoted version argument
Type: behavior Stage: needs patch
Components: Windows Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Maxime Belanger, copelnug, eryksun, paul.moore, steve.dower, terry.reedy, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2018-07-31 17:40 by copelnug, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg322802 - (view) Author: Francois Godin (copelnug) Date: 2018-07-31 17:40
Using double quote around the version argument will cause a failure.

Ex (failure): "py.exe" "-3" "test.py" 
=> run_child: about to run '3" "...\python.exe" "test.py"'
=> ...\python.exe: can't open file '3 test.py': [Errno 22] Invalid argument

Removing the double quote give (success): "py.exe" -3 "test.py" => run_child: about to run '"...\python.exe" "test.py"'

This is mainly problematic when a library or a tool want to be simpler and simply add double quotes around every parameters. This is impossible to do with the python launcher.

The issue seems to come from the PC/launcher.c file. It is the following line in the function process (around line 1622): command += wcslen(p);

This line is suppose to skip the -3 in the command line so that the rest can be given to python as-is. The problem is that while command come from GetCommandLineW and thus contain quote, p come from __wargv and does not contain the double quote. Thus, the 2 characters "- are skipped instead of -3.
msg323093 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-08-03 22:24
I verified this much:
F:\dev\37>py "-3" -m test.test_idle
(null): can't open file '3 -m test.test_idle': [Errno 2] No such file or directory
History
Date User Action Args
2022-04-11 14:59:04adminsetgithub: 78478
2021-03-17 07:15:06eryksunsettitle: Windows py.exe launcher fail to handle quote correctly -> Windows py launcher fails to handle a quoted version argument
stage: test needed -> needs patch
versions: + Python 3.9, Python 3.10, - Python 3.6, Python 3.7
2020-01-10 20:38:01Maxime Belangersetnosy: + Maxime Belanger
2018-08-03 22:24:37terry.reedysetversions: - Python 2.7, Python 3.4, Python 3.5
nosy: + terry.reedy, eryksun, - eric.araujo, dstufft
messages: + msg323093

components: - Demos and Tools, Distutils
stage: test needed
2018-07-31 17:41:19copelnugsettype: behavior
versions: + Python 2.7, Python 3.4, Python 3.5
2018-07-31 17:40:34copelnugcreate