I have a python
script which runs succesfully from the Linux terminal. I am able to collect the terminal output to a file using a shell script
when I run my python
script.
Now I want to collect the terminal output from the python script
itself. But unable to do so.
I want to do this using
python
only not using anyshell
orunix
scripting
I have done like below in my python file
:
class Tee(object):
def __init__(self, f1, f2):
self.f1, self.f2 = f1, f2
def write(self, msg):
self.f1.write(msg)
self.f2.write(msg)
outfile = open('outfile', 'w')
sys.stdout = outfile
sys.stderr = Tee(sys.stderr, outfile)
This part of code in the python file
prints both stderr
and stdout
to a outfile.
How can I capture the whole terminal output to a single file.