bronx.system.unistd¶
Utilities to work on file descriptors through the standard Linux C layer.
The name of this module is directly inspired from the eponym C library.
Functions¶
- bronx.system.unistd.redirected_stdio(module=<module 'sys' (built-in)>, stdio='stdout', to='/dev/null')[source]¶
Redirect module.stdio to to, e.g. (default): sys.stdout to os.devnull
Usage:
with redirected_stdio(sys, out='stdout', to=filename): print("from Python") import os os.system("echo non-Python applications are also supported")
Warning: Use with care. It will crash if module.stdio is already redirected to a File like object that is not a “real” physical file (e.g. a StringIO object). Because of that, it can not be tested with the unitest module since usual test runner redirect stdout/stderr to memory.
Inspired from: http://stackoverflow.com/questions/5081657/how-do-i-prevent-a-c-shared-library-to-print-on-stdout-in-python