Tuesday, August 3, 2010

Re: Python question about subprocess.Popen() and stdout

On Mon, Aug 2, 2010 at 6:41 PM, Joshua Russo <josh.r.russo@gmail.com> wrote:
I'm creating a wxPython application that the client can run to make
sure the installation stack is functioning properly. I want to include
the unit test processing in this application but I've run into some
difficulties. An additional wrinkle I threw in was that I am using
py2exe so they don't also need to install wxPython, we'll see if that
will actually work or not.

It seems like the most appropriate thing to do is to use
subprocess.Popen() to trigger "manage.py test --noinput". The problem
I am trying to solve is that this runs for a while and I want to
display the stdio output into a text box on the window.

I had this working using django.core.management.call_command but
creating the exe broke the pathing within Django and even some Python
libraries (thus dumping py2exe could be what I need to do).

The problem with switching to Popen is that it expects a file type
object with a fileno() method. The file class cannot be extended in
the stdio instance because you can't write back to the __class__
property. I guess what I need to know is how do I mimic stdout? Stdout
doesn't output to a file, but it still uses the file object. It seems
like I want to open a file object onto a Nul output. Can this be
done?

Thanks
Josh

Ok, so it appears that (in Python 2.5 at least) there is no way to capture the stdout of subprocess.Popen(). I've tried many different suggestions from questions that have already been posted to Stack Overflow and everything either buffers until the end of processing or just plain doesn't work.

So I dumped Py2exe and went back to using django.core.management.call_command() and everything works like a dream.

In case you care.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment