I'm trying to develop an interface used to interact with some programs. I have a windows computer, which will hold the interface, and a Raspberry Pi whcich will launch programs.
I've to use them through SSH, but then to interact with :
- From some text fields, i get parameters for programs, and launch it, connected to the SSH session. The program stay in the waiting state "enter a message :".
- Then the user has to be able to enter a message on another text field from the computer, in order to use this message on the program. Here is the problem.
This is for a wireless communication between 2 raspberrys!
In fact, i've no difficulty to launch the program through any Expect library (expectJ, expect4J, expectIt) but i always fail to enter the message after.
The architecture is :
public SSH(String host, String user, String password) throws Exception {
connection = new JSch();
try {
session = connection.getSession(user, host, 22);
session.setPassword(password);
connection.setConfig("StrictHostKeyChecking", "no");
session.connect();
channel = session.openChannel("shell");
channel.connect();
expect = new ExpectBuilder()
.withOutput(channel.getOutputStream())
.withInputs(channel.getInputStream(), channel.getExtInputStream())
.withEchoInput(System.out)
.withEchoOutput(System.out)
.withExceptionOnFailure()
.build();
} catch (JSchException e) {
System.out.println(e.getMessage());
throw new Exception("Error on session");
}
}
public void exec(String prog) {
try {
expect.sendLine(prog);
} catch (IOException e) {
e.printStackTrace();
}
}
public String send(String cmd){
try {
expect.sendLine(cmd);
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
The return "" should be the acknowlegdment when the programme whill be finished. But the send() always fail and enter the data as a linux command line...! So, i'm searching about a solution, like a "sub-expect" of the expect instance... Like this :
SSH --
|-./udp xxxxx
-|"hello"
-|"132"
|-close()
Anyone has an idea ?
Thanks !