I would like to run a process with subprocess.Popen() and communicate with it through the python shell, like the subprocess.Popen usual behavior. Beside that, I would like to discursively log the STDIN and STDOUT to a logfile.
How can I do it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming discursively means rambling and rambling means all in the same file, then the following snippet is what you requested.
Discursive logging with discrimination of the source and interaction
Override its communicate method like similar question here
Discursive logging with discrimination of the source
First use StringIO instead of files, then subclass StringIO to override its write method to open that appends timestamp and source. Then write a custom compare function that sorts based on timestamp and source, timestamp first and then source Input and then output
Discursive logging
The opposite is shown below
Cursive logging