[New-bugs-announce] [issue47027] subprocess.run(), subprocess.Popen() should accept file descriptor as cwd parameter
Yann Droneaud
report at bugs.python.org
Tue Mar 15 10:55:54 EDT 2022
New submission from Yann Droneaud <ydroneaud at opteya.com>:
subprocess.run() and subprocess.Popen() accepts a cwd= parameter to change directory before running the subprocess.
Unfortunately it's not possible to use a file descriptor to run the subprocess in a directory already opened.
For example:
import os
import subprocess
with os.open('/usr/bin', os.O_RDONLY) as f:
subprocess.run(["ls", "-l"], cwd=f, check=True)
fails with
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.9/subprocess.py", line 505, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.9/subprocess.py", line 1754, in _execute_child
self.pid = _posixsubprocess.fork_exec(
Using a file descriptor instead of path is useful to address TOCTOU issues.
Maybe a mean to convert a file descriptor to a Path-like object would do the trick.
----------
components: Library (Lib)
messages: 415249
nosy: ydroneaud
priority: normal
severity: normal
status: open
title: subprocess.run(), subprocess.Popen() should accept file descriptor as cwd parameter
type: enhancement
versions: Python 3.10, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue47027>
_______________________________________
More information about the New-bugs-announce
mailing list