domainless.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:core-framework 作者: RedhawkSDR 项目源码 文件源码
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'
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号