Skip to content

Commit cc7a330

Browse files
committed
First pass at refactoring shell command
1 parent 26743a7 commit cc7a330

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

cmd2.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,16 @@ def do_shell(self, command):
11431143
"""Execute a command as if at the OS prompt.
11441144
11451145
Usage: shell <command> [arguments]"""
1146-
os.system(command)
1146+
try:
1147+
out = subprocess.check_output(shlex.split(command))
1148+
except subprocess.CalledProcessError as e:
1149+
self.perror(e, traceback_war=False)
1150+
except FileNotFoundError as e:
1151+
self.perror(e, traceback_war=False)
1152+
else:
1153+
if six.PY3:
1154+
out = out.decode()
1155+
self.stdout.write(out + '\n')
11471156

11481157
def path_complete(self, text, line, begidx, endidx, dir_exe_only=False, dir_only=False):
11491158
"""Method called to complete an input line by local file system path completion.

0 commit comments

Comments
 (0)