def redirectSTDOUT(filename):
if _DEBUG == True:
print "redirectSTDOUT(): redirecting stdout/stderr to filename " + str(filename)
if type(filename) == str:
dirname = os.path.dirname(filename)
if len(dirname) == 0 or \
(len(dirname) > 0 and os.path.isdir(dirname)):
try:
f = open(filename,'w')
# Send stdout and stderr to provided filename
sys.stdout = f
sys.stderr = f
except Exception, e:
print "redirectSTDOUT(): ERROR - Unable to open file " + str(filename) + " for writing stdout and stderr " + str(e)
elif type(filename) == cStringIO.OutputType:
sys.stdout = filename
sys.stderr = filename
else:
print 'redirectSTDOUT(): failed to redirect stdout/stderr to ' + str(filename)
print 'redirectSTDOUT(): argument must be: string filename, cStringIO.StringIO object'
评论列表
文章目录