Unixライクな環境を仮定すると、あなたはscript
コマンドを使用して、すべてのtty
の入力と出力をキャプチャすることができます。たとえば、以下のユースケースでは、capture.logの4行目にも存在していなければならない)(助けます:
:質問の例では、Pythonは
stdin
パイプによって完全に駆動され、目標がパイプ入力とPythonの出力をキャプチャすることであるよう
$ script capture.log
Script started, output file is capture.log
$ python3
# python interactive session here
$ exit
Script done, output file is capture.log
$ cat capture.log
Script started on Thu Aug 18 21:21:55 2016
$ python3
Python 3.5.2 (default, Jul 21 2016, 07:25:19)
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> help()
Welcome to Python 3.5'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.5/tutorial/.
....
....
>>> ^D
$ exit
Script done on Thu Aug 18 21:22:06 2016
、あなたはtee
コマンドを使用して近づくことができ、場合
$ echo "help()" | tee capture.log | python3 -i >> capture.log 2>&1
$ cat capture.log
help()
Python 3.5.2 (default, Jul 21 2016, 07:25:19)
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Welcome to Python 3.5'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.5/tutorial/.
....
....
ご覧のとおり、入力と出力の両方がキャプチャされていますが、それらは整列していません。