diff options
| author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-03-20 20:20:44 -0400 |
|---|---|---|
| committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-03-20 20:20:44 -0400 |
| commit | 361774895ac825b5f12a38b5bd0ab784cc9a3e95 (patch) | |
| tree | af8cf1f7cfda4e8bbb80d1b9371450b982a24326 /cmd2.py | |
| parent | 62d558db96f103e598880c796b54fb30dd220d2c (diff) | |
| download | cmd2-git-361774895ac825b5f12a38b5bd0ab784cc9a3e95.tar.gz | |
Expanded do_shell parsing of command
Diffstat (limited to 'cmd2.py')
| -rwxr-xr-x | cmd2.py | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -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 |
