spct_utils.py 文件源码

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

项目:specton 作者: somesortoferror 项目源码 文件源码
def runCmd(cmd,cmd_timeout=300):
    ''' run command without showing console window on windows - return stdout and stderr as strings '''
    startupinfo = None
    output = ""
    output_err = ""
    debug_log("runCmd: {}".format(cmd))
    if os.name == 'nt':
        startupinfo = subprocess.STARTUPINFO()
        startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    try:
        proc = subprocess.Popen(cmd,bufsize=-1,startupinfo=startupinfo,stdout=subprocess.PIPE,stderr=subprocess.PIPE,stdin=None,shell=False,universal_newlines=False)
    except SubprocessError as e:
        proc = None
        debug_log("exception in runCmd: {}".format(e),logging.ERROR)
    if proc is not None:
        try:
            outputb, output_errb = proc.communicate()
            output = outputb.decode('utf-8','replace')
            output_err = output_errb.decode('utf-8','replace')
        except subprocess.TimeoutExpired(timeout=cmd_timeout):
            proc.kill()
            debug_log("runCmd: Process killed due to timeout",logging.WARNING)
    else:
        debug_log("runCmd: Proc was none",logging.WARNING)
    return output,output_err
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号