how do I read everything currently in a subprocess.stdout pipe and then return?
Question: I'm using python's subprocess module to interact with a program via the stdin
and stdout pipes. If I call the subprocesses readline() on stdout, it hangs
because it is waiting for a newline.

How can I do a read of all the characters in the stdout pipe of a subprocess
instance? If it matters, I'm running in Linux.


Answer: Someone else appears to have had the same problem, you can see the related
discussion [here](http://stackoverflow.com/questions/375427/non-blocking-read-
on-a-stream-in-python).

If you are running on Linux you can use select to wait for input on the
process' stdout. Alternatively you change the mode of the process' stdout to
non-blocking using

    
    
    import fcntl, os 
    fcntl.fcntl(your_process.stdout, fcntl.F_SETFL, os.O_NONBLOCK)
    

after which you can loop using read() until you encounter a newline character
(if you want to process the output one line at a time).

