summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-07-02 11:13:33 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2017-07-02 11:13:33 -0400
commit91fc975ba2bf0414624aa9c263ddf441beadfa3d (patch)
treea4c7489d7d2f96a588b2d262f844038e9414acbd
parent9054a211b60f55e00ea446433444c0bf4970a50f (diff)
downloadcmd2-git-91fc975ba2bf0414624aa9c263ddf441beadfa3d.tar.gz
Removed unnecessary try/except in do_shell
Since in the subprocess.Popen() call, shell=True and stderr=sys.stderr, errors get printed on stderr. There is no need to catch an exception.
-rw-r--r--CHANGES.md1
-rwxr-xr-xcmd2.py11
2 files changed, 4 insertions, 8 deletions
diff --git a/CHANGES.md b/CHANGES.md
index 82b4a59e..af114bda 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -22,6 +22,7 @@ News
* ``load`` command has better error checking and reporting
* Clipboard copy and paste functionality is now handled by the **pyperclip** module
* NOTE: This adds an additional required 3rd-party dependency
+ * ``shell`` command now supports redirection and piping of output
* Added a lot of unit tests
0.7.3
diff --git a/cmd2.py b/cmd2.py
index 9d1a7160..87a28cd2 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -479,9 +479,7 @@ class Cmd(cmd.Cmd):
self.initial_stdout = sys.stdout
self.history = History()
self.pystate = {}
- # noinspection PyUnresolvedReferences
- self.keywords = self.reserved_words + [fname[3:] for fname in dir(self)
- if fname.startswith('do_')]
+ self.keywords = self.reserved_words + [fname[3:] for fname in dir(self) if fname.startswith('do_')]
self.parser_manager = ParserManager(redirector=self.redirector, terminators=self.terminators,
multilineCommands=self.multilineCommands,
legalChars=self.legalChars, commentGrammars=self.commentGrammars,
@@ -1142,11 +1140,8 @@ class Cmd(cmd.Cmd):
"""Execute a command as if at the OS prompt.
Usage: shell <command> [arguments]"""
- try:
- proc = subprocess.Popen(command, stdout=self.stdout, stderr=sys.stderr, shell=True)
- proc.communicate()
- except FileNotFoundError as e:
- self.perror(e.strerror, traceback_war=False)
+ proc = subprocess.Popen(command, stdout=self.stdout, stderr=sys.stderr, shell=True)
+ proc.communicate()
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.