如何在 Windows 命令行上捕获 python 交互会话?

如何在 Windows 命令行上捕获 python 交互会话?

我想在启动 python shell 后“记录”控制台窗口上显示的所有文本(python shell 提示、我的命令、python shell 输出)。

我读过关于 powershell 的Tee 对象但是python | tee -filename C:\Path\To\SessionLogfile.txt在 powershell 中运行后,从 python 会话中写出的唯一文本SessionLogfile.txt是我的 python 命令的输出。

例如,我期望在中看到这一点SessionLogfile.txt

Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello World")
>>> Hello World
quit()

而我看到的却是:

Hello World

Tee-Object 是否有效并不重要。我只是对捕获会话感兴趣。当我想在发出 python 命令时将文档字符串发送到文件时,它很有用 >>> help(someclass)

相关内容