4646execute_kwargs = set (('istream' , 'with_extended_output' ,
4747 'with_exceptions' , 'as_process' , 'stdout_as_string' ,
4848 'output_stream' , 'with_stdout' , 'kill_after_timeout' ,
49- 'universal_newlines' , 'shell' ))
49+ 'universal_newlines' , 'shell' , 'env' ))
5050
5151log = logging .getLogger (__name__ )
5252log .addHandler (logging .NullHandler ())
@@ -471,6 +471,7 @@ def execute(self, command,
471471 with_stdout = True ,
472472 universal_newlines = False ,
473473 shell = None ,
474+ env = None ,
474475 ** subprocess_kwargs
475476 ):
476477 """Handles executing the command on the shell and consumes and returns
@@ -514,6 +515,9 @@ def execute(self, command,
514515 decoded into a string using the default encoding (usually utf-8).
515516 The latter can fail, if the output contains binary data.
516517
518+ :param env:
519+ A dictionary of environment variables to be passed to `subprocess.Popen`.
520+
517521 :param subprocess_kwargs:
518522 Keyword arguments to be passed to subprocess.Popen. Please note that
519523 some of the valid kwargs are already set by this method, the ones you
@@ -559,6 +563,7 @@ def execute(self, command,
559563 cwd = self ._working_dir or os .getcwd ()
560564
561565 # Start the process
566+ inline_env = env
562567 env = os .environ .copy ()
563568 # Attempt to force all output to plain ascii english, which is what some parsing code
564569 # may expect.
@@ -567,6 +572,8 @@ def execute(self, command,
567572 env ["LANGUAGE" ] = "C"
568573 env ["LC_ALL" ] = "C"
569574 env .update (self ._environment )
575+ if inline_env is not None :
576+ env .update (inline_env )
570577
571578 if is_win :
572579 cmd_not_found_exception = OSError
0 commit comments