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

ⅰ亾dé卋堺 提交于 2019-12-05 18:36:58

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!