Dec-02-2020, 12:33 AM
Don't use line 12 until you want to stop text from going to the file.
The way you have it set, you redirect stdout, then immediately switch it back.
the
Also, don't need to issuefor each command unless you need to process what's being saved.
You can change the open command to be unbuffered by using (on line 13)
Then you should be able to open the savefile is i/o mode (r+) and read what's going on.
I haven't tried this, and not sure if it will lead to file pointer problems, but so long as you're
using a single thread, all should be OK.
The way you have it set, you redirect stdout, then immediately switch it back.
the
sys.stdout = hold_stdout
statement shouldn't be issued until you've captured all that you want to.Also, don't need to issuefor each command unless you need to process what's being saved.
You can change the open command to be unbuffered by using (on line 13)
sys.stdout = open(savefile, 'w', buffering=0)
Then you should be able to open the savefile is i/o mode (r+) and read what's going on.
I haven't tried this, and not sure if it will lead to file pointer problems, but so long as you're
using a single thread, all should be OK.