@@ -2680,7 +2680,8 @@ def _clean_args(self, args):
2680
2680
return self ._clean
2681
2681
2682
2682
def run_command (self , args , check_rc = False , close_fds = True , executable = None , data = None , binary_data = False , path_prefix = None , cwd = None ,
2683
- use_unsafe_shell = False , prompt_regex = None , environ_update = None , umask = None , encoding = 'utf-8' , errors = 'surrogate_or_strict' ):
2683
+ use_unsafe_shell = False , prompt_regex = None , environ_update = None , umask = None , encoding = 'utf-8' , errors = 'surrogate_or_strict' ,
2684
+ expand_user_and_vars = True ):
2684
2685
'''
2685
2686
Execute a command, returns rc, stdout, and stderr.
2686
2687
@@ -2718,6 +2719,11 @@ def run_command(self, args, check_rc=False, close_fds=True, executable=None, dat
2718
2719
python3 versions we support) otherwise a UnicodeError traceback
2719
2720
will be raised. This does not affect transformations of strings
2720
2721
given as args.
2722
+ :kw expand_user_and_vars: When ``use_unsafe_shell=False`` this argument
2723
+ dictates whether ``~`` is expanded in paths and environment variables
2724
+ are expanded before running the command. When ``True`` a string such as
2725
+ ``$SHELL`` will be expanded regardless of escaping. When ``False`` and
2726
+ ``use_unsafe_shell=False`` no path or variable expansion will be done.
2721
2727
:returns: A 3-tuple of return code (integer), stdout (native string),
2722
2728
and stderr (native string). On python2, stdout and stderr are both
2723
2729
byte strings. On python3, stdout and stderr are text strings converted
@@ -2756,8 +2762,11 @@ def run_command(self, args, check_rc=False, close_fds=True, executable=None, dat
2756
2762
args = to_text (args , errors = 'surrogateescape' )
2757
2763
args = shlex .split (args )
2758
2764
2759
- # expand shellisms
2760
- args = [os .path .expanduser (os .path .expandvars (x )) for x in args if x is not None ]
2765
+ # expand ``~`` in paths, and all environment vars
2766
+ if expand_user_and_vars :
2767
+ args = [os .path .expanduser (os .path .expandvars (x )) for x in args if x is not None ]
2768
+ else :
2769
+ args = [x for x in args if x is not None ]
2761
2770
2762
2771
prompt_re = None
2763
2772
if prompt_regex :
0 commit comments