def exec_command(command, timeout=None, **kwargs):
try:
proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=sys.stderr, **kwargs)
except FileNotFoundError:
log.error('No such file or directory: %s', command)
sys.exit(1)
except PermissionError:
log.error('Permission denied: %s', command)
sys.exit(1)
try:
answer, _ = proc.communicate(timeout=timeout)
except subprocess.TimeoutExpired:
answer = b''
return answer, proc
# We should use this instead of posixpath.normpath
# posixpath.normpath doesn't collapse a leading duplicated slashes. see: https://stackoverflow.com/questions/7816818/why-doesnt-os-normpath-collapse-a-leading-double-slash
评论列表
文章目录