David Nicolson wrote:
> This might do what you want to achieve. It seems to make py2exe crash
> on exit, some file locking error. Works fine otherwise though.
>
> #!/usr/bin/env python
>
> import sys
>
> class LogBuffer:
> def __init__(self):
> pass
>
> def flush(self):
> sys.__stdout__.flush()
>
> def write(self,string):
> string = string.strip()
> sys.__stdout__.write("Captured: "+string+"\n")
>
> if __name__ == "__main__":
> logbuffer = LogBuffer()
> sys.stdout = logbuffer
> print "Hello"
>
>
I've written a class called 'StandOut' which does exactly this (plus
more). It works fine with py2exe.
http://www.voidspace.org.uk/python/standout.html
Michael Foord
http://www.voidspace.org.uk
> On 27/10/2006, at 5:48 PM, Johan Lindvall wrote:
>
>
>> Hi,
>>
>> Is there any way of capturing or displaying stdout when running a
>> Python script? I know about:
>>
>> import sys
>> sys.stdout = open("logfile.txt", "a")
>>
>> but I don't want to modify my scripts to achieve this.
>>
>> --
>> /Johan.
>> _______________________________________________
>> Python-win32 mailing list
>> [email protected]
>> http://mail.python.org/mailman/listinfo/python-win32
>>
>
>
>
> _______________________________________________
> Python-win32 mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/python-win32
>
>
_______________________________________________
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32