0
다음 코드를 사용하여 인쇄 문을 텍스트 파일로 리디렉션합니다.하위 프로세스에서 인쇄를 로그 파일로 리디렉션
old_stdout = sys.stdout
log_file = open("message.log","w")
sys.stdout = log_file
print "this will be written to message.log"
subprocess.call("iPython.exe", "script.py") #subprocesses here take this form
sys.stdout = old_stdout
log_file.close()
내 문제는이 방법이 하위 프로세스에는 적용되지 않는 것입니다. "script.py"의 print 문은 "message.log"에 나타나지 않습니다. 그들이 그렇게 할 수 있도록 어떻게 만들 수 있습니까?
더 나은 옵션 일 수있는 로깅을위한 특정 라이브러리가 있습니다 - https://docs.python.org/2/library/logging.html – thefragileomen