Python, why can't i override Popen.stdout -
Why is it possible to override sys.stdout but not the subproduction. Popen.stdout, if it is possible to override my own class, please let me know how ...
I am working on some GUI projects, and I am in "real_time" I want to print some other program's output on text_view when everything does not happen
When I override sys.stdout, I like something like this:
Class MyStdOut: def __init __ (self): self.text = "" def write (self, string): self.text + = string here are some programs' pyscr Ipt.py '
import is OS DIF main (): i in range (10): print i OS system (' SO 0.1 ') ## This is to make some delays, I have 3 Also have loops if __name__ == '__main__': main () and here is the main program:
as sub def (main) Import subprocals: popen = sub.Popen ('./pyscript.py', stdout = sub.PIPE) Line in Popen.stdout: Print 'Line:', line print 'Main done' if __name__ == ' __main__ ': main () However, this is not' real time ', I
Do Nne also tried to communicate, but to get the same results.
In my real program, I have to print the output of other programs on text_view (GUI GTK +). I suspect that the subprocess should be a .steadout file, but when I tried to create some classes from Iobis I inherited the errors as well.
Everyone says that this is possible, but still I tried in several different ways to try the success.
You can get it by using:
p Popen (args, ..., stdout = subprocess.PIPE) for line in P.stdout: print line where p.stdout behaves like a pipe So that you can read the data from it as soon as possible. This real time is not strict, because some buffering comes into play, but still it is a viable option.
Comments
Post a Comment