try: sys.stdout.write(" ") sys.stdout.flush() except IOError: class dummyStream: ''' dummyStream behaves like a stream but does nothing. ''' def __init__(self): pass def write(self,data): pass def read(self,data): pass def flush(self): pass def close(self): pass # and now redirect all default streams to this dummyStream: sys.stdout = dummyStream() sys.stderr = dummyStream() sys.stdin = dummyStream() sys.__stdout__ = dummyStream() sys.__stderr__ = dummyStream() sys.__stdin__ = dummyStream()