47
47
execute_kwargs = set (('istream' , 'with_extended_output' ,
48
48
'with_exceptions' , 'as_process' , 'stdout_as_string' ,
49
49
'output_stream' , 'with_stdout' , 'kill_after_timeout' ,
50
- 'universal_newlines' , 'shell' ))
50
+ 'universal_newlines' , 'shell' , 'env' ))
51
51
52
52
log = logging .getLogger (__name__ )
53
53
log .addHandler (logging .NullHandler ())
@@ -597,6 +597,7 @@ def execute(self, command,
597
597
with_stdout = True ,
598
598
universal_newlines = False ,
599
599
shell = None ,
600
+ env = None ,
600
601
** subprocess_kwargs
601
602
):
602
603
"""Handles executing the command on the shell and consumes and returns
@@ -640,6 +641,9 @@ def execute(self, command,
640
641
decoded into a string using the default encoding (usually utf-8).
641
642
The latter can fail, if the output contains binary data.
642
643
644
+ :param env:
645
+ A dictionary of environment variables to be passed to `subprocess.Popen`.
646
+
643
647
:param subprocess_kwargs:
644
648
Keyword arguments to be passed to subprocess.Popen. Please note that
645
649
some of the valid kwargs are already set by this method, the ones you
@@ -685,6 +689,7 @@ def execute(self, command,
685
689
cwd = self ._working_dir or os .getcwd ()
686
690
687
691
# Start the process
692
+ inline_env = env
688
693
env = os .environ .copy ()
689
694
# Attempt to force all output to plain ascii english, which is what some parsing code
690
695
# may expect.
@@ -693,6 +698,8 @@ def execute(self, command,
693
698
env ["LANGUAGE" ] = "C"
694
699
env ["LC_ALL" ] = "C"
695
700
env .update (self ._environment )
701
+ if inline_env is not None :
702
+ env .update (inline_env )
696
703
697
704
if is_win :
698
705
cmd_not_found_exception = OSError
0 commit comments