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