Controlling an external program with Python

Alexandre Ferrieux alexandre.ferrieux at rd.francetelecom.fr
Tue Jun 27 11:20:40 EDT 2000


Paul Duffin wrote:
> 
> > 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 ?

Last time I checked it was a pty-4.0.tar.gz .
I find it currently with FTPSearch at
ftp://ftp.sunsite.org.uk/Mirrors/wuarchive.wustl.edu/languages/c/unix-c/kernel/pty4.tar.gz
.

Surely more recent/portable variants must exist...

> > 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.


In unix, AFAIK the only nonportable part is the *naming* of the pty
devices. That kind of decision is fairly trivial to make in
sh/awk/perl/python/tcl...

> Windows is also a real problem as it
> does not have ptys and needs to be approached in a completely 
> different way.

Yes but Expect for Windows is a totally different distrib too :-(

Hence the suggestion to consider writing a specific Python module (if
there isn't already - I've just arrived in town): for unix it just opens
the proper devices and substitutes the popen2() pipes with the masters;
for windows more trickery is needed (namely, behaving as a debugger to
trap IO calls!), but should be doable in win32all, shouldn't it ?

For the Mac, er.. ;-)

-Alex



More information about the Python-list mailing list