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