On 21.07.2017 10:03, Jian wrote: > > Then, I have tried this method. It works. I got the text print from > the file. below are the code I used following your advice. > > import sys > original = sys.stdout > sys.stdout = open('redirect.txt', 'w') > ... > other code! > ... > sys.stdout.close() > sys.stdout = original > > But it still not exactly what I expected. Because the text printed to > the file can't be read into the program at the same time.
Then don't redirect to a file; redirect to a buffer that you can attach to your text output widget. The object assigned to `sys.stdout` doesn't have to be a file, it only needs to be a "file-like" object. So, typically you'd use something like StringIO, or, as is done by the document I pointed you to, a GUI widget directly (see section "Redirecting stdout in wxPython"). > > As you mentioned you are not familiar with Windows. I guess you are > using Linux. So could you give me some advice if it can be done in > C/C++ in Linux? See above. The problem is entirely unrelated to the platform you are running on. I was just commenting on the approach you had taken, which was Windows-specific. > > Thanks again for your kind help. > Best Regards, > > Jian Stefan -- ...ich hab' noch einen Koffer in Berlin... _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org https://mail.python.org/mailman/listinfo/cplusplus-sig