하위 프로세스를 사용하여 sox (오디오 처리 프로그램)를 호출하는 Python CGI 스크립트를 작성하려고합니다. 문제는 sox 호출에서 오류가 발생하면 모든 것이 충돌하고 Apache에서 "잘못된 헤더"오류가 발생한다는 것입니다.파이썬 CGI 스크립트에서 하위 프로세스의 오류를 어떻게 잡을 수 있습니까?
관련 비트 :
def downsample(in_file, in_location, sox, out_location):
""" run sox """
...
sox = shlex.split(sox)
retcode = subprocess.check_call(sox)
if not retcode == 0:
print '<b>something went wrong in sox: returned error code ' +\
retcode + ', but we are continuing anyway...</b>'
"""p = subprocess.Popen(sox)
if p.stdout:
print '<b>something happened in sox: returned ' +\
p.stdout.read() + ', but we will keep going...</b>'
if p.stderr:
print '<b>something happened in sox: returned ' +\
p.stderr.read() + ', but we will keep going...</b>'"""
...
def main():
print "Content-Type: text/html\n\n"
...
downsample(in_file, in_location, command, out_location)
...
if __name__ == '__main__':
main()
나는 (500 페이지를 피하기 위해) 지금 스택 추적을 인쇄 할 CGI 오류 처리기를 허용하도록 check_call을 사용하고 있습니다,하지만 난 정말 잡을 싶습니다 오류, 직접 처리 및 스크립트로 이동하십시오. try : calledProcessError : 문을 제외하고 check_call을 래핑하여 시도했지만 500 페이지로 다시 넘어갔습니다. 주석 처리 된 부분도 저에게 효과적이지 않습니다.
그리고는/var/www가에서/아파치/error_log는 : 그것은 전에 헤더 인쇄를 삭스 명령 을 실행하는 것 같다 왜 이해할 수 없다Wed Apr 13 10:08:21 2011] [error] [client ::1] sox FAIL formats: can't open input file `/tmp/wavs/haha/f.wav': WAVE: RIFF header not found, referer: http://localhost/~Valkyrie_savage/
[Wed Apr 13 10:08:21 2011] [error] [client ::1] malformed header from script. Bad header=\x1f\x8b\b: downsample.py, referer: http://localhost/~Valkyrie_savage/
. 그렇지 않은 경우 헤더의 형식이 잘못되었다고 말하는 이유는 무엇입니까?
고마워요! 그것은 매력처럼 작용했습니다. –