def ex_subprocess(cmd):
"""subprocess wrapper function
Arguments:
- cmd (list(str)): the command to feed the subprocess
Return:
(out, compl_proc, error_proc) (3-uple):
- out (int) : 1 suprocess fail, 0 subprocess succeed
- compl_proc (subprocess.CompletedProcess instance): return value
of the subprocess when it has succeeded
- error_proc (subprocess.CalledProcessError instance): value of the
subprocess when an Exception has occured
"""
out = 1
compl_proc = None
error_proc = None
try:
compl_proc = subprocess.run(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, check=True)
except subprocess.CalledProcessError as error:
error_proc = error
else:
out = 0
finally:
return out, compl_proc, error_proc
评论列表
文章目录