[issue37515] `open("aux.txt", "w")` fails unexpectedly with FileNotFoundError on Windows
Eryk Sun
report at bugs.python.org
Sat Jul 6 15:27:10 EDT 2019
Eryk Sun <eryksun at gmail.com> added the comment:
DOS device names are reserved in the final component of DOS drive-letter paths. "AUX" (plus an optional colon, spaces, or extension) becomes "\\.\AUX", which is "\??\AUX" in the NT object namespace. By default, "\??\AUX" is a link to "\??\COM1", which, if it exists, is typically a link to "\Device\Serial0". If there's no "COM1", then the kernel returns STATUS_OBJECT_NAME_NOT_FOUND, which the Windows API translates to ERROR_FILE_NOT_FOUND, which the C runtime translates to ENOENT, and finally Python raises FileNotFoundError.
Accessing a DOS device name requires using a device path (prefixed by "\\.\" or "\\?\", and forward slash is okay, e.g. "//./C:/Temp/aux.py") or a UNC path (e.g. "//localhost/C$/Temp/aux.py"). That said, if we create a file like this, programs that use regular drive-letter paths won't be able to access it. It's better to sanitize reserved DOS device names. This includes "CONIN$" and "CONOUT$", even though Microsoft's documentation overlooks these two.
----------
nosy: +eryksun
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37515>
_______________________________________
More information about the Python-bugs-list
mailing list