diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-07-02 09:27:02 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-07-02 09:27:02 -0400 |
commit | cc7a3303e1c95f713e84cf3bbd6acf262823e3a2 (patch) | |
tree | f984c42bdf3984a3ea1a5af306a7214d8ffbdca0 /cmd2.py | |
parent | 26743a702afa42ff199614def9f7c5eb04308f76 (diff) | |
download | cmd2-git-cc7a3303e1c95f713e84cf3bbd6acf262823e3a2.tar.gz |
First pass at refactoring shell command
Diffstat (limited to 'cmd2.py')
-rwxr-xr-x | cmd2.py | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -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. |