什么是 Expect 能做而 Pexpect 不能做的?

发布于 2024-09-15 10:47:50 字数 348 浏览 21 评论 0原文

我正在考虑开始使用 Pexpect。在 Pexpects 主页上我发现了这个:

问:为什么不直接使用 Expect?

答:我喜欢 它。这很棒。我已将我保释出境 一些真正的果酱,但我想要一些东西 这可以满足我90%的需要 预计;为尺寸的 10%;并允许 我用 Python 编写代码 TCL 的。 Pexpect 没有那么大 与 Expect 一样,但 Pexpect 可以完成所有操作 我曾经使用过 Expect for。

Pexpect 和 Expect 之间存在 10% 的差异。所以我的问题是这 10% 的差异是什么?什么是 Expect 能做而 Pexpect 不能做的事情?

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别再吹冷风 2024-09-22 10:47:50

这个问题(“什么是 Expect 能做而 Pexpect 不能做的事情”)有点误导。这并不是说 Pexpect 不能做 Expect 可以做的事情;而是说 Pexpect 不能做 Expect 可以做的事情。而是 Expect 有很多额外的支持来让这种编程变得更容易。

举个例子,以交互命令为例,它允许用户直接与生成的进程交互。在Pexpect 中,这就是interact 所做的全部事情。 (正如您所说,这可能足以满足您的需求。)相比之下,Expect 的交互支持在交互期间检测模式、将多个生成的进程挂钩在一起等。当然,您可以通过自己编码来完成所有这些操作。但是你的代码会更长——有时会长很多,因为你本质上必须重写你自己的交互,你必须调试它,等等。事实上,你可能已经遇到过这些情况,但没有意识到要简单得多等效的 Expect 代码是。

当然,额外的支持可能会被您对 Python 的偏好所抵消。 :-P

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文