Enable runcmd to use a list for the command, and have it quote elements as needed.

This commit is contained in:
Robin Dunn
2016-07-22 14:28:00 -07:00
parent 5e8f4b1264
commit 648e5789fc
2 changed files with 29 additions and 8 deletions

View File

@@ -781,6 +781,24 @@ def getVcsRev():
def runcmd(cmd, getOutput=False, echoCmd=True, fatal=True):
"""
Runs a give command-line command, optionally returning the output.
"""
if isinstance(cmd, list):
# add quotes to elements of the command that need it
cmd = cmd[:]
for idx, item in enumerate(cmd):
if ' ' in item or ';' in item:
if item[0] not in ['"', "'"]:
if '"' in item:
item = item.replace('"', '\\"')
item = '"{}"'.format(item)
cmd[idx] = item
cmd = ' '.join(cmd)
#if echoCmd:
# msg(' '.join(cmd))
if echoCmd:
msg(cmd)