icanfly / expect4j

Automatically exported from code.google.com/p/expect4j
Apache License 2.0
0 stars 0 forks source link

Non-deterministic behaviour with Expect4j #1

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Expect4j is really a good project.

In following code snippet, I am trying to login to terminal server. somehow
I have to wait little bit ( 5 seconds) between 'send' and 'expect',
otherwise 'expect' function throws exception of type 'Exception'. If I
execute code in debug mode, I do not need Thread.sleep.

-----------------
expect.expect("login:");

if (expect.getLastState().getMatch() == null) {

    throw new LoginFailedException(

    "Login to NS Failed, someone is already logged in");

}

expect.send("nsroot" + "\r");

Thread.sleep(2 * 1000); //Somehow Expect4j does not work without this delay
in execution.

expect.expect("Password:");

if (expect.getLastState().getMatch() == null) {

    throw new LoginFailedException("Login to NS Failed");

}

expect.send("nsroot" + "\r");

------------------------

Thanks.
Jay

Original issue reported on code.google.com by pateljay...@gmail.com on 28 Jul 2008 at 7:11

GoogleCodeExporter commented 9 years ago
What should I understand when 'expect' function throws exception of type
'Exception'.? I am really not able to debug this as in debug mode I do not need
Thread.sleep and expect function works fine. I am very unclear what is going on.
Thanks a lot. Hope to hear from you soon.

Thanks.
Jay

Original comment by pateljay...@gmail.com on 28 Jul 2008 at 7:15

GoogleCodeExporter commented 9 years ago
Jay, you really saved my day. I was banging my head since morning to get the my 
code working. It was trying this tutorial 
http://nikunjp.wordpress.com/2011/07/30/remote-ssh-using-jsch-with-expect4j/ 
and it was working fine in debug mode but while running it was giving following 
error 
        expect4j.BlockingConsumer run
        INFO: Stop Requested
then I used your trick of 'Thread.sleep(2 * 1000);'
thanks a lot.

Original comment by kush.di...@gmail.com on 22 Jan 2013 at 12:05