Controlling an external program with Python

Paul Duffin pduffin at hursley.ibm.com
Wed Jun 28 07:12:32 EDT 2000


Alexandre Ferrieux wrote:
> 
> Paul Duffin wrote:
> > 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...
> 

I think that you will find that there is a lot more too it than that, there
are all sorts of different ways of controlling / configuring the ptys,
defaults are different ...

> > 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 :-(
> 

But the interface is the same.

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

Apparently there is a port of Expect for Python so why not use that
rather than try and reimplement it all over again. If you wanted to
be really nice you could create a library containing a nice abstract 
representation of ttys which hides all of the nastiness and then create
a simple binding to that library.

Expect has over 7 years of development and centuries of testing on many
different platforms, do you really want to reproduce that. If so why,
what exactly is wrong with Expect.



More information about the Python-list mailing list