Paul Wills
asked on
expectj telnet failing
Hi Experts
I trying to run a simple telnet to my local server using expectj. It fails with an error:
"java.io.IOException: Cannot run program "localhost": error=2, No such file or directory"
Please see the code below:
public void TelnetTest(){
try {
ExpectJ ex = new ExpectJ(5);
Spawn sh = ex.spawn("localhost\n");
System.out.println("expect ingogin:") ;
sh.expect("login:");
System.out.println("sendin gaha");
sh.send("username\n");
System.out.println("expect ingassword :");
sh.expect("password:");
System.out.println("sendin gasswd");
sh.send("passwd\n");
System.out.println("expect ingogin Failed");
sh.expect("Login failed");
//sh.expectClose();
sh.stop();
}
catch(TimeoutException te){
System.out.println("Time!! ");
}
catch(Exception e) {
System.out.println(e);
}
Thank you in advance.
I trying to run a simple telnet to my local server using expectj. It fails with an error:
"java.io.IOException: Cannot run program "localhost": error=2, No such file or directory"
Please see the code below:
public void TelnetTest(){
try {
ExpectJ ex = new ExpectJ(5);
Spawn sh = ex.spawn("localhost\n");
System.out.println("expect
sh.expect("login:");
System.out.println("sendin
sh.send("username\n");
System.out.println("expect
sh.expect("password:");
System.out.println("sendin
sh.send("passwd\n");
System.out.println("expect
sh.expect("Login failed");
//sh.expectClose();
sh.stop();
}
catch(TimeoutException te){
System.out.println("Time!!
}
catch(Exception e) {
System.out.println(e);
}
Thank you in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi CEHJ
Thank you for your assistance. I had to pass in the hostname with the telnet command like this:
Spawn telnet = ex.spawn("/usr/bin/telnet localhost 7898");
Thank you for your assistance. I had to pass in the hostname with the telnet command like this:
Spawn telnet = ex.spawn("/usr/bin/telnet localhost 7898");
:)
Looks like the following will give you telnet too:
Looks like the following will give you telnet too:
Spawn telnet = ex.spawn("localhost", 7898);
ASKER
Thank you CEHJ, much appreciated.
ASKER
I tried that, I want to be able to telnet to remote servers. The question now is; where do I put the remote host IP or hostname to telnet to?