tools: add 'shell' parameter to 'run()' (#2950)

This commit is contained in:
Bert Belder 2019-09-15 16:47:37 +02:00
parent e7d1da3671
commit 456b75cbf9
No known key found for this signature in database
GPG key ID: 7A77887B2E2ED461

View file

@ -49,14 +49,16 @@ def add_env_path(add, env, key="PATH", prepend=False):
env[key] = os.pathsep.join(dirs_left)
def run(args, quiet=False, cwd=None, env=None, merge_env=None):
if merge_env is None:
merge_env = {}
def run(args, quiet=False, cwd=None, env=None, merge_env=None, shell=None):
args[0] = os.path.normpath(args[0])
if not quiet:
print " ".join(args)
env = make_env(env=env, merge_env=merge_env)
shell = os.name == "nt" # Run through shell to make .bat/.cmd files work.
if shell is None:
# Use the default value for 'shell' parameter.
# - Posix: do not use shell.
# - Windows: use shell; this makes .bat/.cmd files work.
shell = os.name == "nt"
if not quiet:
print " ".join([shell_quote(arg) for arg in args])
rc = subprocess.call(args, cwd=cwd, env=env, shell=shell)
if rc != 0:
sys.exit(rc)