summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-07-02 09:27:02 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2017-07-02 09:27:02 -0400
commitcc7a3303e1c95f713e84cf3bbd6acf262823e3a2 (patch)
treef984c42bdf3984a3ea1a5af306a7214d8ffbdca0
parent26743a702afa42ff199614def9f7c5eb04308f76 (diff)
downloadcmd2-git-cc7a3303e1c95f713e84cf3bbd6acf262823e3a2.tar.gz
First pass at refactoring shell command
-rwxr-xr-xcmd2.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/cmd2.py b/cmd2.py
index b04bf215..66e4716f 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -1143,7 +1143,16 @@ class Cmd(cmd.Cmd):
"""Execute a command as if at the OS prompt.
Usage: shell <command> [arguments]"""
- os.system(command)
+ try:
+ out = subprocess.check_output(shlex.split(command))
+ except subprocess.CalledProcessError as e:
+ self.perror(e, traceback_war=False)
+ except FileNotFoundError as e:
+ self.perror(e, traceback_war=False)
+ else:
+ if six.PY3:
+ out = out.decode()
+ self.stdout.write(out + '\n')
def path_complete(self, text, line, begidx, endidx, dir_exe_only=False, dir_only=False):
"""Method called to complete an input line by local file system path completion.