0001 # This is a helper for the win32trace module 0002 0003 # If imported from a normal Python program, it sets up sys.stdout and sys.stderr 0004 # so output goes to the collector. 0005 0006 # If run from the command line, it creates a collector loop. 0007 0008 # Eg: 0009 # C:>start win32traceutil.py (or python.exe win32traceutil.py) 0010 # will start a process with a (pretty much) blank screen. 0011 # 0012 # then, switch to a DOS prompt, and type: 0013 # C:>python.exe 0014 # Python 1.4 etc... 0015 # >>> import win32traceutil 0016 # Redirecting output to win32trace remote collector 0017 # >>> print "Hello" 0018 # >>> 0019 # And the output will appear in the first collector process. 0020 0021 # Note - the client or the collector can be started first. 0022 # There is a 64k buffer. If this gets full, it is reset, and new 0023 # output appended from the start. 0024 0025 import win32trace 0026 0027 def RunAsCollector(): 0028 import sys 0029 try: 0030 import win32api 0031 win32api.SetConsoleTitle("Python Trace Collector") 0032 except: 0033 pass # Oh well! 0034 win32trace.InitRead() 0035 print "Collecting Python Trace Output..." 0036 # import win32api;win32api.DebugBreak() 0037 while 1: 0038 # print win32trace.blockingread() 0039 sys.stdout.write(win32trace.blockingread()) 0040 0041 0042 def SetupForPrint(): 0043 win32trace.InitWrite() 0044 try: # Under certain servers, sys.stdout may be invalid. 0045 print "Redirecting output to win32trace remote collector" 0046 except: 0047 pass 0048 win32trace.setprint() # this works in an rexec environment. 0049 0050 if __name__=='__main__': 0051 RunAsCollector() 0052 else: 0053 SetupForPrint() 0054
Generated by PyXR 0.9.4