我希望能够捕获Python shell的输出以及发送给它的输入。例如,在以下用例中,help() 应该出现在 capture.log 的第四行:
$ echo "help()" | python3 -i > capture.log 2>&1
$ cat capture.log
Python 3.4.2 (default, Oct 8 2014, 10:45:20)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Welcome to Python 3.4's help utility!
If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/3.4/tutorial/.
....
....