如何实现期望“互动”用java命令 [英] how to implement expect "interact" command using java

查看:131
本文介绍了如何实现期望“互动”用java命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用java实现expectinteract命令。在期望中,可以打开ssh会话,进行身份验证,然后使用interact命令将控件返回给用户。这有可能与Java?我已经尝试过expectJ,expect4J和expectForJava但是文档很少,几乎没有如何做到这一点的例子。 TIA。

I want to implement the expect "interact" command using java. In expect, it's possible to open an ssh session, authenticate and, then, use the "interact" command to give the control back to the user. Is that possible with java? I've tried with expectJ, expect4J and expectForJava but there's little documentation and almost no examples of how to do this. TIA.

更新:对于互动命令参考,请检查一下: http://wiki.tcl.tk/3914

Update: for "interact" command reference, please check this out: http://wiki.tcl.tk/3914


Interact是一个Expect命令,它提供控制权对用户当前的
进程,以便将键击发送到当前的
进程,并且当前进程的stdout和stderr返回

"Interact is an Expect command which gives control of the current process to the user, so that keystrokes are sent to the current process, and the stdout and stderr of the current process are returned."


推荐答案

如果有人感兴趣,我已经为 ExpectIt ,我自己的开源Expect for Java实现(对不起自我推销),自0.8版以来。

In case anyone is interested, I have added basic interactive loop support to ExpectIt, my own open source Expect for Java implementation (sorry for self-promotion), since version 0.8.

这是示例

        try (final Expect expect = new ExpectBuilder()
                .withInputs(System.in)
                .build()) {
            expect.interact()
                    .when(contains("abc")).then(r -> System.out.println("A"))
                    .when(contains("xyz")).then(r -> System.err.println("B"))
                    .until(contains("exit"));
            System.out.println("DONE!");
        }
        System.in.close();

这篇关于如何实现期望“互动”用java命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆