diff options
-rw-r--r-- | CHANGES.md | 1 | ||||
-rwxr-xr-x | cmd2.py | 8 | ||||
-rw-r--r-- | tests/test_cmd2.py | 4 |
3 files changed, 5 insertions, 8 deletions
@@ -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 @@ -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, @@ -1138,12 +1136,12 @@ class Cmd(cmd.Cmd): Usage: pause [text]""" sm.input(text + '\n') - # noinspection PyMethodMayBeStatic def do_shell(self, command): """Execute a command as if at the OS prompt. Usage: shell <command> [arguments]""" - os.system(command) + 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. diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 592e6af2..9dd2697b 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -103,12 +103,10 @@ To enable full traceback, run the following command: 'set debug true' def test_base_shell(base_app, monkeypatch): m = mock.Mock() - monkeypatch.setattr("os.system", m) + monkeypatch.setattr("subprocess.Popen", m) out = run_cmd(base_app, 'shell echo a') assert out == [] assert m.called - m.assert_called_with('echo a') - def test_base_py(base_app, capsys): run_cmd(base_app, 'py qqq=3') |