Running a command line program and reading the result as it runs

Ian Simcock Ian.Simcock at Internode.on.net
Fri Aug 23 02:52:08 EDT 2013


Chris Angelico wrote:
> On Fri, Aug 23, 2013 at 1:26 AM, Ian Simcock
> <Ian.Simcock at internode.on.net> wrote:
>> Chris Angelico wrote:
>>>
>
> A lot of programs, when their output is not going to the console, will
> buffer output. It's more efficient for many purposes. With Unix
> utilities, there's often a parameter like --pipe or --unbuffered that
> says "please produce output line by line", but Windows ping doesn't
> have that - and so I'm seeing the same thing you are.
>
> You should be able to see the time delay in dir by looking for some
> particular directory name, and searching from the root directory.
> Unless you're on a BLAZINGLY fast drive, that'll take Windows a good
> while!
>
> ChrisA

I tried it again with the dir command and, while my drive is pretty 
fast, it does look like it works.

I've done come looking around and found that the standard C libraries 
apparently automatically buffer output when the output is being 
redirected to a file handle unless specifically told not to.

I did a further test and created a unique file name in the root of my D 
drive and then use dir to search the entire drive for that name. In the 
command window the name appears instantly and then after a slight pause 
the command prompt reappears. When run from python however the pause 
comes first and then the name appears and then the command prompt returns.

So yep, seems like I'm screwed :-)

Thanks for your help with this. At least now I know it's not that I'm 
doing something wrong.

Ian Simcock.




More information about the Python-list mailing list