Getting no output from shell in serial mode using streams
- Dominant language
- Java
- Stars
- 2.7k
- Forks
- 620
- Avg merge
- 3d 23h
- Merged PRs (30d)
- 11
Description
I'm trying to implement an application that uses SSH to secure a simple json serial interface to a device. On this device the default shell has been replaced by an application to handle this protocol. You open the shell, send a JSON command, and get a JSON response.
Everything seems fine in SSHJ, but I never see expected responses to my commands.
The code looks like:
public void connect () {
try {
ssh = new SSHClient();
ssh.loadKnownHosts();
ssh.connect( host );
ssh.authPublickey( user );
boolean isAuthed = ssh.isAuthenticated();
session = ssh.startSession();
session.allocateDefaultPTY();
shell = session.startShell();
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
}
}
public void write( String message ) {
DataOutputStream stream_to_dev = new DataOutputStream( shell.getOutputStream() );
try {
stream_to_dev.writeBytes( message + (char)0x0d + (char)0x0a );
} catch (IOException e) {
e.printStackTrace();
}
}
public String read () {
DataInputStream stream_from_dev = new DataInputStream( shell.getInputStream());
boolean open = shell.isOpen();
InputStream errorstream = shell.getErrorStream();
ByteArrayOutputStream buf = new ByteArrayOutputStream();
try
{
if( stream_from_dev.available() != 0 )
{
while( stream_from_dev.available() != 0 )
{
int result = stream_from_dev.read();
byte b = (byte)result;
buf.write(b);
}
return buf.toString();
}
else
{
System.out.println("Nothing in the buffer...");
return "";
}
}
catch (IOException e)
{
e.printStackTrace();
return "";
}
}
The only response I've ever seen is "Nothing in the buffer..." on the console. Is SSHJ respecting the overridden shell command on the device, or going with some other default?
An example showing stream IO like above (without interactive StreamCopier stuff in the PTY example) would be very helpful.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.