code: def _tempfilepager(generator, cmd, color):
      
      import tempfile
      filename = tempfile.mktemp()
      # TODO: This never terminates if the passed generator never terminates.
      text = "".join(generator)
      if not color:
          text = strip_ansi(text)
      encoding = get_best_encoding(sys.stdout)
      with open_stream(filename, 'wb')[0] as f:
          f.write(text.encode(encoding))
      try:
          os.system(cmd + ' "' + filename + '"')
      finally:
          os.unlink(filename)
docs: Page through text by invoking a program on a temporary file.