diff options
-rw-r--r-- | cmd2/cmd2.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 5aeb4fdf..72784d4c 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -2109,10 +2109,13 @@ class Cmd(cmd.Cmd): :param saved_state: contains information needed to restore state data """ if saved_state.redirecting: + delete_name = None # If we redirected output to the clipboard if statement.output and not statement.output_to: self.stdout.seek(0) write_to_paste_buffer(self.stdout.read()) + if statement.output == constants.REDIRECTION_APPEND: + delete_name = self.stdout.name try: # Close the file or pipe that stdout was redirected to @@ -2120,6 +2123,10 @@ class Cmd(cmd.Cmd): except BrokenPipeError: pass + # If we appended to the clipboard, make sure to delete the tempfile + if delete_name is not None: + os.unlink(delete_name) + # Restore the stdout values self.stdout = saved_state.saved_self_stdout sys.stdout = saved_state.saved_sys_stdout |