def safe_system(command, catch_sigpipe=False):
popen = Popen(
args = safe_popen_args(command),
shell = False,
preexec_fn = lambda: signal(SIGPIPE, SIG_DFL),
)
status = popen.wait() # pylint: disable-msg=E1101
if status == 0:
return status # ??? OK
if catch_sigpipe:
if status & 128 == 128 and status & 127 == SIGPIPE:
return status # bash ??????? ???, ??? ??? ????? ?????? SIGPIPE
elif status < 0 and -status == SIGPIPE:
return status # bash ????? ?????? SIGPIPE
# ?????? bash ?????? fork/exec ?????? ?????? exec (???????????, ?? ??????
# ????? ????? ????????? ???? ??????? ???????) ? ????? ??????? ??? ????????
# ???, ??? ????? ?????? ?????? ???, ???? ?? ????? ???? ???? ??? ????? ???.
# ?????-?? ?????? (???????? ?? SIGPIPE ??? catch_sigpipe=True)
raise SafePopenError(command, status)
评论列表
文章目录