Why does reading from a shell channel output in JSch never end with -1? Why does reading from a shell channel output in JSch never end with -1? shell shell

Why does reading from a shell channel output in JSch never end with -1?


The "shell" channel opens a shell.

We do not know what your code actually does. But I'd assume that you send some command to the shell to be executed and then you try to read the command output. And you probably expect to get -1 once the command output ends. You won't.

The shell output stream ends, only when the shell ends. And for that you need to send some command like exit.


In general, you should not use the "shell" channel. It's intended for implementing an interactive shell session (like if you are implementing your own SSH terminal). That's something you rarely do.

To automate a command execution, use the "exec" channel.

See also What is the difference between the 'shell' channel and the 'exec' channel in JSch.