4747execute_kwargs = set (('istream' , 'with_extended_output' ,
4848 'with_exceptions' , 'as_process' , 'stdout_as_string' ,
4949 'output_stream' , 'with_stdout' , 'kill_after_timeout' ,
50- 'universal_newlines' , 'shell' ))
50+ 'universal_newlines' , 'shell' , 'env' ))
5151
5252log = logging .getLogger (__name__ )
5353log .addHandler (logging .NullHandler ())
@@ -597,6 +597,7 @@ def execute(self, command,
597597 with_stdout = True ,
598598 universal_newlines = False ,
599599 shell = None ,
600+ env = None ,
600601 ** subprocess_kwargs
601602 ):
602603 """Handles executing the command on the shell and consumes and returns
@@ -640,6 +641,9 @@ def execute(self, command,
640641 decoded into a string using the default encoding (usually utf-8).
641642 The latter can fail, if the output contains binary data.
642643
644+ :param env:
645+ A dictionary of environment variables to be passed to `subprocess.Popen`.
646+
643647 :param subprocess_kwargs:
644648 Keyword arguments to be passed to subprocess.Popen. Please note that
645649 some of the valid kwargs are already set by this method, the ones you
@@ -685,6 +689,7 @@ def execute(self, command,
685689 cwd = self ._working_dir or os .getcwd ()
686690
687691 # Start the process
692+ inline_env = env
688693 env = os .environ .copy ()
689694 # Attempt to force all output to plain ascii english, which is what some parsing code
690695 # may expect.
@@ -693,6 +698,8 @@ def execute(self, command,
693698 env ["LANGUAGE" ] = "C"
694699 env ["LC_ALL" ] = "C"
695700 env .update (self ._environment )
701+ if inline_env is not None :
702+ env .update (inline_env )
696703
697704 if is_win :
698705 cmd_not_found_exception = OSError
0 commit comments