Grabbing the output of a long-winded shell call (in GNU/Linux)

draghuram at gmail.com draghuram at gmail.com
Tue May 1 15:31:25 EDT 2007


On May 1, 2:23 pm, Efrat Regev <efrat_re... at yahoo.com> wrote:

> So my question is if there's a way to "grab" the output as it's being
> generated. It doesn't matter if the solution is blocking (as opposed to
> callback based), since threads can handle this. I just don't know how to
> "grab" the output. I appreciate your time in reading (and answering
> this), as I've been googling several hours for this.

There may be more pythonic solution than what I suggest here but this
is what I have done when I needed similar functionality. Basically run
your command in the background and redirect its stdout/err to a temp
file. You may run the command either in the background or in a
separate thread. You can then run the command "tail --retry --
pid=<pid> -n+0 -F <output_file>" and grab the output. The tail command
exits once the real command is done.

Raghu.







More information about the Python-list mailing list