[issue39857] subprocess.run: add an extra_env kwarg to complement existing env kwarg
Mike Frysinger
report at bugs.python.org
Wed Mar 4 21:10:18 EST 2020
New submission from Mike Frysinger <vapier at users.sourceforge.net>:
a common idiom i run into is wanting to add/set one or two env vars when running a command via subprocess. the only thing the API allows currently is inherting the current environment, or specifying the complete environment. this means a lot of copying & pasting of the pattern:
env = os.environ.copy()
env['FOO'] = ...
env['BAR'] = ...
subprocess.run(..., env=env, ...)
it would nice if we could simply express this incremental behavior:
subprocess.run(..., extra_env={'FOO': ..., 'BAR': ...}, ...)
then the subprocess API would take care of copying & merging.
if extra_env:
assert env is None
env = os.environ.copy()
env.update(extra_env)
this is akin to subprocess.run's capture_output shortcut.
it's unclear to me whether this would be in both subprocess.Popen & subprocess.run, or only subprocess.run. it seems like subprocess.Popen elides convenience APIs.
----------
components: Library (Lib)
messages: 363413
nosy: vapier
priority: normal
severity: normal
status: open
title: subprocess.run: add an extra_env kwarg to complement existing env kwarg
type: enhancement
versions: Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39857>
_______________________________________
More information about the Python-bugs-list
mailing list