регистрировать синтаксические ошибки и неперехваченные исключения для подпроцесса python и выводить их на терминал

The Problem

Я пытался написать программу, которая регистрирует необработанные исключения и синтаксические ошибки для подпроцесса. Легко, правда? Просто трубаstderr в нужное место.

Howeverподпроцесс - это другая программа на Python, которую я назовуtest.py- это должно работать так, как будто его вывод / ошибки не фиксируются. То есть запуск программы регистрации должен выглядеть так, как будто пользователь только что запустилpython test.py как обычно.

Дальнейшее осложнение вопросаэта проблема тотraw_input на самом деле отправляетсяstderr еслиreadline не используется К сожалению, я не могу простоimport readline, поскольку я не могу контролировать файлы, которые запускаются с помощью моего регистратора ошибок.

Notes:

I am fairly restricted on the machines that this code will run on. I can't install pexpect or edit the *customize.py files (since the program will be run by a lot of different users). I really feel like there should be a stdlib solution anyway though... This only has to work on macs. The motivation for this is that I'm part of a team researching the errors that new programmers get. What I've Tried

Я безуспешно пробовал следующие способы:

just using tee as in the question How do I write stderr to a file while using "tee" with a pipe? (failed to produce raw_input prompts); python implementations of tee that I found in several SO questions had similar issues overwriting sys.excepthook (failed to make it work for a subprocess) this question's top answer seemed promising, but it failed to display raw_input prompts correctly. the logging module seems useful for actually writing to a log file, but doesn't seem to get at the crux of the issue custom stderr readers endless googling

Ответы на вопрос(2)

Ваш ответ на вопрос