Bluntly, the original Expect--the Tcl Expect--is the best one. It better supports "interact" and various pty eccentricities than any of its successors. It has no superior, for what it does.
HOWEVER, at the same time, most Expect users exploit such a small fraction of Expect's capabilities that this technical superiority is a matter of indifference to them. In nearly all cases, I advise someone coming from Perl to use Expect.pm, someone familiar with Python to rely on Pexpect, and so on.
Naive comparisons of Perl with "... Awk and also Perl" are ill-founded.
In the abstract, all the common scripting languages--Lua, awk, sh, Tcl, Ruby, Perl, Python, ...--are about the same. Expect slightly but very effectively extends this common core in the direction of pty-awareness (there's a little more to the story that we can neglect for the moment). Roughly speaking, if your automation involves entering an invisible password, you want Expect. Awk and Perl do NOT build in this capability.
There are other automation tools for other contexts.
ajsie asks, "Which other automation tools are you talking about?"
I'll answer a different question: "which other contexts do I have in mind"? The answer: any interactive environment OTHER than a stdio one. Expect is NOT for automation of GUI points-and-clicks, for example. Expect is also not available for Win* non-console applications, even if they look as though they are character-oriented (such exist).
An exciting counter-realization: Expect is for automation of wacky equipment that permits control by a term-like connection. If your diesel engine (or, more typically, telecomm iron) says it can be monitored by hooking up a telnet-like process (even through an old-style serial line, say), you're in a domain where Expect has a chance to work its magic.
发布评论
评论(4)
还有更多。
坦率地说,最初的 Expect——Tcl Expect——是最好的。与它的任何后继者相比,它更好地支持“交互”和各种 pty 怪癖。就其所做的事情而言,它没有优越者。
然而,与此同时,大多数 Expect 用户只利用了 Expect 功能的一小部分,因此这种技术优势对他们来说并不重要。几乎在所有情况下,我建议来自 Perl 的人使用 Expect.pm,熟悉 Python 的人依赖 Pexpect,等等。
将 Perl 与“... Awk 和 Perl”进行天真的比较是没有根据的。
抽象地说,所有常见的脚本语言——Lua、awk、sh、Tcl、Ruby、Perl、Python……——都是差不多的。期待稍微但非常有效地将这个共同核心扩展到 pty 意识的方向(这个故事还有一些我们暂时可以忽略的内容)。粗略地说,如果您的自动化涉及输入不可见的密码,那么您需要 Expect。 Awk 和 Perl 不内置此功能。
还有其他适用于其他情况的自动化工具。
There's more to it.
Bluntly, the original Expect--the Tcl Expect--is the best one. It better supports "interact" and various pty eccentricities than any of its successors. It has no superior, for what it does.
HOWEVER, at the same time, most Expect users exploit such a small fraction of Expect's capabilities that this technical superiority is a matter of indifference to them. In nearly all cases, I advise someone coming from Perl to use Expect.pm, someone familiar with Python to rely on Pexpect, and so on.
Naive comparisons of Perl with "... Awk and also Perl" are ill-founded.
In the abstract, all the common scripting languages--Lua, awk, sh, Tcl, Ruby, Perl, Python, ...--are about the same. Expect slightly but very effectively extends this common core in the direction of pty-awareness (there's a little more to the story that we can neglect for the moment). Roughly speaking, if your automation involves entering an invisible password, you want Expect. Awk and Perl do NOT build in this capability.
There are other automation tools for other contexts.
查看 Perl 的 Expect
Check out Expect for Perl
ajsie 问道:“您还在谈论哪些其他自动化工具?”
我将回答一个不同的问题:“我还考虑到哪些其他情况”?答案是:除了 stdio 之外的任何交互式环境。例如,Expect 不适用于 GUI 点击的自动化。 Expect 也不适用于 Win* 非控制台应用程序,即使它们看起来像是面向字符的(存在这种情况)。
一个令人兴奋的反现实:期望是古怪设备的自动化,允许通过类似术语的连接进行控制。如果您的柴油发动机(或更典型的是电信铁)表示可以通过连接类似 telnet 的进程(甚至通过旧式串行线路)来监控它,那么您就处于 Expect 有机会的域中发挥其魔力。
ajsie asks, "Which other automation tools are you talking about?"
I'll answer a different question: "which other contexts do I have in mind"? The answer: any interactive environment OTHER than a stdio one. Expect is NOT for automation of GUI points-and-clicks, for example. Expect is also not available for Win* non-console applications, even if they look as though they are character-oriented (such exist).
An exciting counter-realization: Expect is for automation of wacky equipment that permits control by a term-like connection. If your diesel engine (or, more typically, telecomm iron) says it can be monitored by hooking up a telnet-like process (even through an old-style serial line, say), you're in a domain where Expect has a chance to work its magic.
查看 Python 的 Pexpect
Check out Pexpect for Python