[issue25481] PermissionError in subprocess.check_output() when an inaccessible directory on the path
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Eryk Sun <eryksun@gmail.com> added the comment:
So, two interesting questions: does this in fact match the behavior of os._execvpe, and does it match the behavior of the shell?
I think it's fine. child_exec() tries all paths. It saves the first error that's not ENOENT or ENOTDIR. The saved error gets reported back, else ENOENT or ENOTDIR. This is the same as os._execvpe: for dir in path_list: fullname = path.join(dir, file) try: exec_func(fullname, *argrest) except (FileNotFoundError, NotADirectoryError) as e: last_exc = e except OSError as e: last_exc = e if saved_exc is None: saved_exc = e if saved_exc is not None: raise saved_exc raise last_exc Perhaps the rule for PATH search errors should be documented for os.execvp[e] and subprocess. I think it matches the shell, except, AFAIK, the shell doesn't distinguish ENOENT and ENOTDIR errors. For example, where "/noexec" is a directory that has no execute access: $ /bin/sh -c spam /bin/sh: 1: spam: not found $ PATH=/noexec:$PATH /bin/sh -c spam /bin/sh: 1: spam: Permission denied ---------- assignee: -> docs@python components: +Documentation, Library (Lib) nosy: +docs@python versions: +Python 3.10, Python 3.8, Python 3.9 -Python 3.5 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue25481> _______________________________________
participants (1)
-
Eryk Sun