Jump to content
  • Advertisement
Sign in to follow this  

Java Can't read non-CR lines from inputstream

This topic is 2510 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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.

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);
}
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!