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

Efrat Regev efrat_regev at yahoo.com
Tue May 1 14:23:40 EDT 2007


   Hello,

   Suppose I want to run from within a Python GUI app some long-output 
shell call. For example, from within Python I might want to call

g++ foo.cpp

   I already know there are many ways to do this, e.g., 
commands.getstatusoutput('g++ foo.cpp') to name one.

   The problem is that this might generate a ton of output (e.g., 
because of compilation errors), and might take a while to do so. In my 
GUI, I'd like to print out the output as it's being generated, not wait 
until all is done (as commands.getstatusoutput will do) and dump it at 
once.

   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.


   Many Thanks,

   E



More information about the Python-list mailing list