Ruby 是否有一个 Expect 等效 gem?
Ruby 是否有一个 Expect 等效 gem?
我尝试在 code.google 和 rubygems.org 上搜索,但遗憾的是它没有出现。
仅供参考:Expect 是一个 Unix 自动化和测试工具,由 Don Libes 编写,作为 Tcl 脚本语言的扩展,用于交互应用程序,例如 telnet、ftp、passwd、fsck、rlogin、tip、ssh 等。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Ruby 附带了 PTY 模块,用于设置伪终端驱动交互式命令行应用程序。随之而来的是一个
expect
方法 允许您与类似 Expect 的应用程序进行交互。为了学习如何使用expect,我找到了“Ruby Expect 库会带来什么?”有帮助。就宝石而言,也许可以查看 greenletters ,它应该在 PTY + 的基础上进行改进 + 期望(尽管我还没有)我自己尝试过)。
Ruby comes with the PTY module for setting up pseudoterminals to drive interactive command line applications. With it comes an
expect
method that allows you to interact with an application kinda like Expect. For learning how to use expect, I found "What to expect from the Ruby expect library?" helpful.As far as gems go, maybe checkout greenletters which is supposed to improve upon PTY + expect (although I haven't tried it myself).
我最近花了相当多的时间来解决这个问题(我被 1.8.7 困住了)。我发现这个问题,这个博客文章和这个论坛帖子非常有用。
最后,如果有人对一个小例子感兴趣的话,这是我的应用程序代码(在签名包时将密码传递给 rpm):
它几乎没有错误检查,但这就是我所需要的。
编辑:使用 Process.wait(pid) 更新代码,以确保它在继续之前完成,并添加有关 1.8.7 的注释。
I recently spent quite a bit of time struggling with this issue (I am stuck with 1.8.7). I found this question, this blog post and this forum thread really useful.
At the end this is my application code if anyone is interested in a little example (pass the password to rpm when signing packages):
It has little error checking but it was all I needed.
Edit: Update the code with
Process.wait(pid)
to make sure it finishes before continuing and add comment about this being for 1.8.7.查看这个 rubygem:https://github.com/abates/ruby_expect。它可以为你处理一些小任务。从其官方示例来看,“输入密码”并登录并与本地脚本交互就足够了。
这是一个更新 git 代码(使用密码进行身份验证)的示例:
只需运行上面的代码,您将看到如下内容:
有关更多示例和详细信息,请深入研究其源代码。
checkout this rubygem: https://github.com/abates/ruby_expect. It could handle some small task for you. from its official example, it's enough to 'enter password' and login and interactive with local script.
here is an example that update the git code (which is authenticated with password):
just run the code above, and your will see like this:
for more example and details, please dive into its source code.
expect4r 似乎可以满足您的要求,尽管它是专门用于与 Cisco 和 Juniper 设备的连接的。
也许更好的是 yax 因为这是“另一个期望”。
expect4r seems to do what you are asking for, though it is made specific for connections to Cisco and Juniper devices.
Perhaps even better is yax as this is "yet another expect".
RExpect
来自项目的网站:
RExpect
From the project's website:
parley 是另一种你可以尝试的方法(由我编写)。它的灵感来自 Perl Expect。
parley is another one you can try, (written by me). It is inspired by Perl expect.