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:41:14 -07:00
parent 648e5789fc
commit 09d4d817e6
2 changed files with 4 additions and 7 deletions

View File

@@ -788,16 +788,14 @@ def runcmd(cmd, getOutput=False, echoCmd=True, fatal=True):
# 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 ' ' in item or '\t' in item or ';' in item:
if item[0] not in ['"', "'"]:
if '"' in item:
item = item.replace('"', '\\"')
item = '"{}"'.format(item)
cmd[idx] = item
# convert the resulting command to a string
cmd = ' '.join(cmd)
#if echoCmd:
# msg(' '.join(cmd))
if echoCmd:
msg(cmd)