1

I'm trying to write a ssh application for android using sshj. I can connect to a server and read from the inputstream without problems, getting something like:

Welcome to Ubuntu 12.04.1 LTS (GNU/Linux 3.2.0.29-generic x86_64)

Documentation: https://help.ubuntu.com/

Last login: date time from user`

Normally I would expect to get an input prompt in the format of user@host:~$ now, put the inputstream just ends here. I am able to write to the shell and execute commands without problems, but I am really bothered about not getting the input prompt as it is kind of helpful to know when to write to the outputstream and for proper formatting. When I execute a command the prompt is written into the inputstream and it looks like this:

"executed command"

user@host:~$ "executed command"

"result"`

I tried reading with readline() as well as read() and checked if the stream has any data available for reading.

Is there any way for me to receive the prompt from the inputstream without executing a command?

Murgi
  • 31
  • 5

1 Answers1

2

This problem can be circumvented by using a StreamCopier as shown in the 'RudimentaryPTY' example and redirecting the System.out to a PrintStream:

    baos = new ByteArrayOutputStream();
    ps= new PrintStream(baos);
    System.setOut(ps);
    new StreamCopier (shell.getInputStream(),System.out).bufSize(shell.getLocalMaxPacketSize()).spawn("stdout");
    textView.setText(baos.toString("UTF8"));

This solution is definitely not perfect, but it works. I am still open for suggestion on how to do this better!

Murgi
  • 31
  • 5