Sign in to follow this  
Belgium

Java Can't read non-CR lines from inputstream

Recommended Posts

Hello,

I'm using Ganymed to establish an SSH telnet session. I am able to read the information
coming from the telnet session as long as there is a carriage return.

I can send 'whoami' and read the response since it has a carriage return.

However, when I send 'passwd' the response does not contain a carriage return and I cannot read it.
I also can't read the ' it uses as a prompt for my input as it also doesn't have a carriage return.
What can I do to get all the bytes and not just those which end with a carriage return?

As a side issue, what's the point of .available()? It seems to always return 0 even though there
is stuff to be read. I've read "The available method for class InputStream always returns 0." so what's the point?

Below is what I am using to read the stream.

Thanks.

[code]InputStream m_input = new StreamGobbler(m_session.getStdout());
InputStream m_error = new StreamGobbler(m_session.getStderr());
String m_inputText = "";

byte[] buff = new byte[4096];

while(true)
{
try
{
if (m_input.available() > -1)
{
int len = in.read(buff);
if (len == -1)
{
break;
}
m_inputText += new String(buff, 0, len);
}
}
catch (Exception e)
{
LogFile.print(e);
}
} [/code]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this