I had to change the interface a little (in the head now and will be in the nightly build tonight):
char[] buffer = new char[ 100 ];
String result = ""; //$NON-NLS-1$
String errResult = ""; //$NON-NLS-1$
SSHPersistantConnection con = new SSHPersistantConnection();
con.createSession( sshConnectionInfo, null );
if ( con.isSessionActive() ) {
con.connect( );
try {
BufferedWriter stdoutWriter = new BufferedWriter( new OutputStreamWriter( con.getOutputStream() ) );
BufferedReader stdoutReader = new BufferedReader( new InputStreamReader( con.getInputStream() ) );
BufferedReader stderrReader = new BufferedReader( new InputStreamReader( con.getErrorStream() ) );
stdoutWriter.write( "ls\n" );
stdoutWriter.flush();
// Might not be needed
try {
Thread.sleep( 1000 );
} catch (InterruptedException e) {
// Ignor for now
}
int read = 0;
while ( stdoutReader.ready() && read != -1 ) {
read = stdoutReader.read( buffer, 0, 100 );
result = result + new String(buffer);
}
read = 0;
while ( stderrReader.ready() && read != -1 ) {
read = stderrReader.read( buffer, 0, 100 );
errResult = errResult + new String(buffer);
}
} catch (IOException e) {
// Ignor for now
}
}
System.out.println( "outPut:\n" + result );
System.out.println( "error:\n" + errResult );