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
评论列表
文章目录