Page through text by invoking a program on a temporary file.
(text, cmd)
| 1703 | pass |
| 1704 | |
| 1705 | def tempfilepager(text, cmd): |
| 1706 | """Page through text by invoking a program on a temporary file.""" |
| 1707 | import tempfile |
| 1708 | with tempfile.TemporaryDirectory() as tempdir: |
| 1709 | filename = os.path.join(tempdir, 'pydoc.out') |
| 1710 | with open(filename, 'w', errors='backslashreplace', |
| 1711 | encoding=os.device_encoding(0) if |
| 1712 | sys.platform == 'win32' else None |
| 1713 | ) as file: |
| 1714 | file.write(text) |
| 1715 | os.system(cmd + ' "' + filename + '"') |
| 1716 | |
| 1717 | def _escape_stdout(text): |
| 1718 | # Escape non-encodable characters to avoid encoding errors later |