This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author manlioperillo
Recipients
Date 2004-06-18.16:42:56
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Logged In: YES 
user_id=1054957

I have found a very simple patch.

First I have implemented this function:


import os

def isrealfile(file):
    """
    Test if file is on the os filesystem
    """
    
    if not hasattr(file, 'fileno'): return False

    try: tmp = os.dup(file.fileno())
    except: return False
    else: os.close(tmp); return True


Microsoft implementation of stdout/err/in when no console is
created (and when no pipes are used) actually are not 'real'
files.

Then I have added the following code in sitecustomize.py:


import sys

class NullStream:
    """
    A file like class that writes nothing
    """
    def close(self): pass
    def flush(self): pass
    def write(self, str): pass
    def writelines(self, sequence): pass

if not isrealfile(sys.__stdout__): 
   sys.stdout = NullStream()

if not isrealfile(sys.__stderr__):
   sys.stderr = NullStream()



I have tested the code only on Windows XP Pro.


P.S.
isrealfile could be added in os module.



Regards   Manlio Perillo
History
Date User Action Args
2008-01-20 09:56:57adminlinkissue973507 messages
2008-01-20 09:56:57admincreate