问题
I am considering to start using Pexpect. On Pexpects homepage I find this:
Q: Why not just use Expect?
A: I love it. It's great. I has bailed me out of some real jams, but I wanted something that would do 90% of what I need from Expect; be 10% of the size; and allow me to write my code in Python instead of TCL. Pexpect is not nearly as big as Expect, but Pexpect does everything I have ever used Expect for.
There is a 10% difference between Pexpect and Expect. So my question is what is this 10% difference. What is it that Expect can do that Pexpect can't.
回答1:
That question ("What is it that Expect can do that Pexpect can't") is a bit misleading. It's not that Pexpect can't do things that Expect can; it's that Expect has a lot of extra support to make this kind of programming easier.
As an example, take the interact command which lets the user interact directly with the spawned process. In Pexpect, that's all interact does. (And that may be sufficient for your needs, as you say.) In contrast, Expect's interact has support for detecting patterns during an interact, hooking together multiple spawned processes, etc. Of course, you can do all this by coding it yourself. But your code will be longer - sometimes a lot longer because you'll essentially have to rewrite your own interact, you'll have to debug it, etc. In fact, you may have encountered these situations already but not realized how much simpler the equivalent Expect code would be.
Of course, the extra support may be more than offset by your preference for Python. :-P
来源:https://stackoverflow.com/questions/3521954/what-can-expect-do-that-pexpect-can-not-do