Controlling an external program with Python

Alexandre Ferrieux alexandre.ferrieux at rd.francetelecom.fr
Tue Jun 27 09:10:06 EDT 2000


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.

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

-Alex



More information about the Python-list mailing list