summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-03-20 20:20:44 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-03-20 20:20:44 -0400
commit361774895ac825b5f12a38b5bd0ab784cc9a3e95 (patch)
treeaf8cf1f7cfda4e8bbb80d1b9371450b982a24326 /cmd2.py
parent62d558db96f103e598880c796b54fb30dd220d2c (diff)
downloadcmd2-git-361774895ac825b5f12a38b5bd0ab784cc9a3e95.tar.gz
Expanded do_shell parsing of command
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/cmd2.py b/cmd2.py
index fb3e0f1f..a8171603 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -2611,7 +2611,20 @@ Usage: Usage: unalias [-a] name [name ...]
"""Execute a command as if at the OS prompt.
Usage: shell <command> [arguments]"""
- proc = subprocess.Popen(command, stdout=self.stdout, shell=True)
+
+ try:
+ tokens = shlex.split(command, posix=POSIX_SHLEX)
+ except ValueError as err:
+ self.perror(err, traceback_war=False)
+
+ for index, token in enumerate(tokens):
+ tokens[index] = strip_quotes(tokens[index])
+ tokens[index] = os.path.expandvars(tokens[index])
+ tokens[index] = os.path.expanduser(tokens[index])
+ tokens[index] = shlex.quote(tokens[index])
+
+ expanded_command = ' '.join(tokens)
+ proc = subprocess.Popen(expanded_command, stdout=self.stdout, shell=True)
proc.communicate()
@staticmethod