On Thu, Aug 5, 2010 at 10:53 PM, Steve Holden <holden...@gmail.com> wrote:
> On 8/5/2010 7:16 PM, Joshua Russo wrote: > > On Aug 4, 6:49 pm, Hassan <hsn.zam...@gmail.com> wrote: > >>> Ok, so it appears that (in Python 2.5 at least) there is no way to > capture > >>> the stdout of subprocess.Popen() > >> > >> just do this > >> > >> from subprocess import Popen, PIPE > >> p = Popen([cmd], stdout=PIPE) > >> p.stdout.readlines() > >> > >> thats it! > > > > The problem is that it waits for the process to end to output > > anything. Unless I was doing something wrong, but I think I was doing > > just what you describe here. > > > Well, readlines() inherently has to see the end of the data stream > before it can return a list of all the lines that the data stream > contains, so that's hardly surprising is it? > > Try using readline() in a loop and see if that gives you better results. > I don't guarantee it will, but at least you will have some chance if > subprocess.open() *isn't* buffering the whole stream. > > regards > Steve Tried that too and even putting the reading of them in their own thread as someone else suggested on Stackoverflow. I just can't find anyway to capture stdout in real-time from Popen. The problem is that everything uses readline() that buffers the output. http://stackoverflow.com/questions/874815/how-do-i-get-real-time-information-back-from-a-subprocess-popen-in-python-2-5 http://stackoverflow.com/questions/2082850/real-time-subprocess-popen-via-stdout-and-pipe The way I got it to work with out Popen is to use a text box control as the stdout object. This works great, utilizing the object's write() method. The problem with Popen is that it expects the stdout object to have a fileno() method also, which the text box control does not have. So I tried extending the text box to add the fileno() and had it return 1 like the standard stdout, but still no dice. I didn't let the process (unit tests) finish but it definitely was not giving real time output, through it did accept the control with the fileno() method added. It really seems like that should have worked and I may have been able to dig further into Popen to make it work but I figured that I had spent too much time on it as it was. If anybody has more suggestions I'd love to hear them. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.