이 질문에 대한 대답 꽤 동안 검색 한 및 많은 내 생각을 subprocess 모듈 어떻게 작동하는지 익숙하지 함께 할 생각합니다. 누구나 관심이있는 경우 퍼징 프로그램을위한 것입니다. 그냥 잘 작동서브 프로세스, 인코딩 및 로깅 sqlite 함께
# open and run a process and log get return code and stderr information
process = subprocess.Popen([app, file_name], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
return_code = process.wait()
err_msg = process.communicate()[1]
# insert results into an sqlite database log
log_cur.execute('''INSERT INTO log (return_code, error_msg)
VALUES (?,?)''', [unicode(return_code), unicode(error_msg)])
log_db.commit()
99 (100)의 시간이 초과하지만 가끔 내가 같은 에러가납니다 또한,이 모든 (내가 그 관련 생각) 나는이 같은 일부 코드를 리눅스에서 수행되고 있음을 언급해야한다 로 :
UnicodeDecodeError 잘못된 연속 바이트
편집 : 'UTF8'코덱 위치 43 바이트 0xce를 디코딩 할 수있는 풀 추적
Traceback (most recent call last):
File "openscadfuzzer.py", line 72, in <module>
VALUES (?,?)''', [crashed, err_msg.decode('utf-8')])
File "/home/username/workspace/GeneralPythonEnv/openscadfuzzer/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xdb in position 881: invalid continuation byte
0,123,516
하위 프로세스, 실행 또는 코드에 사용중인 응용 프로그램에 문제가 있습니까? 모든 포인터는 (특히 서브 프로세스 stdout 및 stderr의 올바른 사용과 관련된 경우) 감사하게 될 것입니다.
해결책이 아님. 단지'wait()'와'communicate()'둘 다 프로세스가 끝날 때까지 기다릴 것이다. 'wait()'호출을 끊고 - (out, err,) = process.communicate() return_code = process.returncode' – RedBaron
과 같은 일을 할 수 있습니다. 어디에서 유니 코드 데코레이터 오류가 발생했는지 보여주는 스택 추적을 할 수 있습니까? – monk
자동 디코딩/인코딩 의미론이 2와 3 사이에서 다르기 때문에 파이썬 버전을 사용하는 것도 가치가 있습니다 (서브 프로세스 라이브러리에서도 마찬가지 일 수 있습니다) – monk