29.08.2009 2:21 пользователь Gabriel Genellina <gagsl-...@yahoo.com.ar>
написал:
En Sat, 29 Aug 2009 03:28:26 -0300, ivanko....@gmail.com> escribió:
Hello to everyone! I am making a program that will be a GTK+ frontend to
ffmpeg. Naturally, one of the main functions is parsing ffmpeg's output.
It's pretty simple when I, for example, retrieve information about a file
(the program finishes and I read the output). But it also needs to parse
working ffmpeg's output (in order to retrieve the percentage, remaining
time, etc.). So, actually what I do is Popen ffmpeg, and connect to its
stdout. And as stdout is represented by a file object, it needs to be
read(). The problem is that read() reads until EOF is reached, which
doesn't exist while the program is running (the same goes with
communicate()).
So my question is: is there a way to retrieve the stdout without waiting
the program to finish?
You don't have to read the complete output at once - you may process it
line by line, I presume. I'd use a second thread to read the pipe and put
the lines onto a Queue object; the main thread gets lines from the Queue
when available.
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list
Thanks, Gabriel, but I resolved that problem in another way. thrashold in
irc.freenode.net gave me the solution.
What i do now is:
p = Popen(["cmd","arg"],stdout=PIPE,stderr=STDOUT)
fcntl.fcntl(p.stdout.fileno(), fcntl.F_SETFL, os.O_NONBLOCK)
p.stdout.read()
And in that way p.stdout.read() doesn't wait the program to finish, but
gives me instant response. But anyway, thanks! =)
--
http://mail.python.org/mailman/listinfo/python-list