diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-04-10 00:18:26 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-04-10 00:18:26 -0400 |
commit | 6e56ad2040b20b5a3b62e0f16ae72be7743d667e (patch) | |
tree | 06653e37d49295a6666cdd03716cef39c340dca6 /cmd2/cmd2.py | |
parent | f5c904cda48c03a30b3476f3a40224226391deea (diff) | |
download | cmd2-git-6e56ad2040b20b5a3b62e0f16ae72be7743d667e.tar.gz |
Pyscript now saves command output during the same period that redirection does
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index ddc3945b..aeaa1543 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -1718,6 +1718,11 @@ class Cmd(cmd.Cmd): try: # Get sigint protection while we set up redirection with self.sigint_protection: + if self._in_py: + # Start saving the command's output at this point to match what redirection captures + self.stdout.pause_storage = False + sys.stderr.pause_storage = False + redir_error, saved_state = self._redirect_output(statement) self.cur_pipe_proc_reader = saved_state.pipe_proc_reader @@ -1763,6 +1768,11 @@ class Cmd(cmd.Cmd): if not already_redirecting: self.redirecting = False + if self._in_py: + # Stop saving command's output before command finalization hooks run + self.stdout.pause_storage = True + sys.stderr.pause_storage = True + except EmptyStatement: # don't do anything, but do allow command finalization hooks to run pass @@ -3026,7 +3036,6 @@ class Cmd(cmd.Cmd): if self._in_py: err = "Recursively entering interactive Python consoles is not allowed." self.perror(err, traceback_war=False) - self._last_result = CommandResult('', err) return False try: |