home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Shareware / Comunicatii / jyte / jyte.exe / win32traceutil.py < prev    next >
Text File  |  2002-01-08  |  1KB  |  54 lines

  1. # This is a helper for the win32trace module
  2.  
  3. # If imported from a normal Python program, it sets up sys.stdout and sys.stderr
  4. # so output goes to the collector.
  5.  
  6. # If run from the command line, it creates a collector loop.
  7.  
  8. # Eg:
  9. # C:>start win32traceutil.py (or python.exe win32traceutil.py)
  10. # will start a process with a (pretty much) blank screen.
  11. #
  12. # then, switch to a DOS prompt, and type:
  13. # C:>python.exe
  14. # Python 1.4 etc...
  15. # >>> import win32traceutil
  16. # Redirecting output to win32trace remote collector
  17. # >>> print "Hello"
  18. # >>>
  19. # And the output will appear in the first collector process.
  20.  
  21. # Note - the client or the collector can be started first.
  22. # There is a 64k buffer.  If this gets full, it is reset, and new
  23. # output appended from the start.
  24.  
  25. import win32trace
  26.  
  27. def RunAsCollector():
  28.     import sys
  29.     try:
  30.         import win32api
  31.         win32api.SetConsoleTitle("Python Trace Collector")
  32.     except:
  33.         pass # Oh well!
  34.     win32trace.InitRead()
  35.     print "Collecting Python Trace Output..."
  36. #    import win32api;win32api.DebugBreak()
  37.     while 1:
  38. #        print win32trace.blockingread()
  39.         sys.stdout.write(win32trace.blockingread())
  40.  
  41.  
  42. def SetupForPrint():
  43.     win32trace.InitWrite()
  44.     try:    # Under certain servers, sys.stdout may be invalid.
  45.         print "Redirecting output to win32trace remote collector"
  46.     except:
  47.         pass
  48.     win32trace.setprint() # this works in an rexec environment.
  49.  
  50. if __name__=='__main__':
  51.     RunAsCollector()
  52. else:
  53.     SetupForPrint()
  54.