Eryk Sun <eryk...@gmail.com> added the comment:

MSYS2 has basically the same problem when the script is passed as a Windows 
path, except it uses "/c" for the "C:" drive instead of "/cygdrive/c".

    # python3 -VV
    Python 3.9.9 (main, Dec 28 2021, 11:05:23)
    [GCC 11.2.0]

    # echo $PWD
    /proc

    # python3 C:/Temp/test.py
    python3: can't open file '/proc/C:/Temp/test.py': [Errno 2] No such file or 
directory

Windows paths in the command-line arguments appear to be passed without 
conversion:

    # python3 -ic 1 C:/Temp/test.py
    >>> import os
    >>> open(f'/proc/{os.getpid()}/cmdline').read().split('\0')
    ['python3', '-ic', '1', 'C:/Temp/test.py', '']

They're generally supported:

    >>> open('C:/Temp/test.py').read()
    'import sys\nprint(sys.executable)\n\n'

    >>> os.path.samefile('C:/Temp/test.py', '/c/Temp/test.py')
    True

    >>> os.path.abspath('C:/Temp/test.py')
    'C:/Temp/test.py'

realpath() doesn't support them:

    >>> os.path.realpath('C:/Temp/test.py')
    '/:/Temp/test.py'

But the C API _Py_wrealpath() does:

    >>> import ctypes
    >>> path = (ctypes.c_wchar * 1000)()
    >>> ctypes.pythonapi._Py_wrealpath('C:/Temp/test.py', path, 1000)
    1484496
    >>> path.value
    '/c/Temp/test.py'

----------
nosy: +eryksun

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46751>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to