Skip to content

Commit 91fc975

Browse files
committed
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.
1 parent 9054a21 commit 91fc975

2 files changed

Lines changed: 4 additions & 8 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ News
2222
* ``load`` command has better error checking and reporting
2323
* Clipboard copy and paste functionality is now handled by the **pyperclip** module
2424
* NOTE: This adds an additional required 3rd-party dependency
25+
* ``shell`` command now supports redirection and piping of output
2526
* Added a lot of unit tests
2627

2728
0.7.3

cmd2.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,7 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, use_ipython=False
479479
self.initial_stdout = sys.stdout
480480
self.history = History()
481481
self.pystate = {}
482-
# noinspection PyUnresolvedReferences
483-
self.keywords = self.reserved_words + [fname[3:] for fname in dir(self)
484-
if fname.startswith('do_')]
482+
self.keywords = self.reserved_words + [fname[3:] for fname in dir(self) if fname.startswith('do_')]
485483
self.parser_manager = ParserManager(redirector=self.redirector, terminators=self.terminators,
486484
multilineCommands=self.multilineCommands,
487485
legalChars=self.legalChars, commentGrammars=self.commentGrammars,
@@ -1142,11 +1140,8 @@ def do_shell(self, command):
11421140
"""Execute a command as if at the OS prompt.
11431141
11441142
Usage: shell <command> [arguments]"""
1145-
try:
1146-
proc = subprocess.Popen(command, stdout=self.stdout, stderr=sys.stderr, shell=True)
1147-
proc.communicate()
1148-
except FileNotFoundError as e:
1149-
self.perror(e.strerror, traceback_war=False)
1143+
proc = subprocess.Popen(command, stdout=self.stdout, stderr=sys.stderr, shell=True)
1144+
proc.communicate()
11501145

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

0 commit comments

Comments
 (0)