Refer: ExpectIt : Trouble implementing a sudo -i
How can I avoid echoing all output of Expectit to my java console?
This is how I started my SSH:
public void connect( String host, String user, String password ) throws Exception {
this.host = host;
this.user = user;
this.password = password;
ssh = new SSHClient();
ssh.addHostKeyVerifier( new PromiscuousVerifier() );
ssh.connect(host, port);
ssh.authPassword(user, password);
session = ssh.startSession();
session.allocateDefaultPTY();
shell = session.startShell();
expect = new ExpectBuilder()
.withOutput(shell.getOutputStream())
.withInputs(shell.getInputStream(), shell.getErrorStream())
.withInputFilters(removeColors(), removeNonPrintable())
.withExceptionOnFailure()
.withTimeout(30, TimeUnit.SECONDS)
.build();
String result = expect.expect( Matchers.contains( PROMPT ) ).getInput();
consoleOut.add( result );
}
Now ALL results taken from Expect will echo to the console. I can take the "result" string, but it goes to tomcat console too (I'm sure I'm not send it to).
expect.sendLine( command );
String result = expect.expect( Matchers.contains( PROMPT ) ).getInput();
I'm running in a Tomcat container (web environment).
You can disable to the command echo by sending the stty -echo
command at the beginning of the session. Take a look at this example.
I suggest to post questions to the ExpectIt user group rather then on Stackoverflow since currently there are only a few people who are using this library.