Controlling an external program with Python

Paul Duffin pduffin at hursley.ibm.com
Tue Jun 27 10:59:00 EDT 2000


Alexandre Ferrieux wrote:
> 
> Paul Duffin wrote:
> >
> > [detailed explanation of stdio-buffering/ttys/pipes]
> >
> > you may want to look into Python versions
> > of Expect. If they are not satisfactory then you could probably write
> > a little Tcl/Expect wrapper around the application which forces the
> > correct buffering and then control that using Python.
> 
> Not withstanding Tcl ;-) honesty commands to also mention the
> existence of the 'pty' unix package, which is roughly "Expect minus
> Tcl", and especially its 'nobuf' tool:
> 
>         nobuf cmd [args...]
> 
> starts cmd as a child, strongly held between ptys, so that the overall
> command behaves properly (ie in unbuffered or line-buffered mode) betwen
> pipes. If all you want is that, Expect is surely an overkill.
> 

Where can I get the 'pty' package from ?

> But ptys are no rocket science anyway. The nobuf above should be doable
> in pure Python within 20 loc...
> 

While ptys are not rocket science they are also not particularly portable,
Expect handles all of this for you. Windows is also a real problem as it
does not have ptys and needs to be approached in a completely different 
way.



More information about the Python-list mailing list