#!/usr/bin/env python # fdsync # # v1.0.0 # # written by: Oliver Cordes 2011-08-17 # updated by: Oliver Cordes 2011-08-17 # fdsync is a missing feature of the bash which can be used to # sync/flush stdout or stderr. We use this to get in sync while # using set -x to get debug information to stderr and piping # stdout and stderr into tee. bash is not doing a flush # automatically, so the resulting output is always a mess. # SYNTAX: # fdsync [file] [[file] ... ] # # Example: # fdsync /dev/stdout or # fdsync /dev/stdout /dev/stderr # import sys for filename in sys.argv[1:]: try: f = open( filename, 'rw', 0 ) except IOError,s: print s sys.exit( 0 ) f.flush() f.close()