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

Efrat Regev efrat_regev at yahoo.com
Tue May 1 15:33:20 EDT 2007


draghuram at gmail.com wrote:
> 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.
> 
> 
> 
> 

Many Thanks! I'll try this



More information about the Python-list mailing list