utils.py 文件源码

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

项目:kuberdock-platform 作者: cloudlinux 项目源码 文件源码
def local_exec(cmd, env=None, shell=False, check_retcode=True):
    LOG.debug("{}Executing locally: '{}'{}".format(
        Style.DIM, cmd if isinstance(cmd, basestring) else " ".join(cmd),
        Style.RESET_ALL))
    if env is not None:
        # Sanitize env because it doees not digest non string values
        env = dict((key, str(value)) for key, value in env.items())
        # Unite the system and custom environments
        env = dict(os.environ, **env)
    proc = subprocess.Popen(cmd, env=env, stderr=subprocess.PIPE,
                            stdout=subprocess.PIPE, shell=shell)
    out, err = proc.communicate()
    ret_code = proc.returncode

    _proceed_exec_result(
        out.decode('ascii', 'ignore'), err.decode('ascii', 'ignore'),
        ret_code, check_retcode)
    return ret_code, out, err
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号