code: def _restore_output(self, statement: Statement, saved_state: utils.RedirectionSavedState) -> None:
          
          if saved_state.redirecting:
              # 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())
  
              try:
                  # Close the file or pipe that stdout was redirected to
                  self.stdout.close()
              except BrokenPipeError:
                  pass
  
              # Restore the stdout values
              self.stdout = saved_state.saved_self_stdout
              sys.stdout = saved_state.saved_sys_stdout
  
              # Check if we need to wait for the process being piped to
              if self.cur_pipe_proc_reader is not None:
                  self.cur_pipe_proc_reader.wait()
  
          # Restore cur_pipe_proc_reader. This always is done, regardless of whether this command redirected.
          self.cur_pipe_proc_reader = saved_state.saved_pipe_proc_reader
docs: Handles restoring state after output redirection as well as
          the actual pipe operation if present.
  
          :param statement: Statement object which contains the parsed input from the user
          :param saved_state: contains information needed to restore state data