New submission from Mike Frysinger <vap...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue39857>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to