Thanks for your reply. I checked the output of my program again, now I confirm that only the last piece of the result can not be returned. For example, if I read 512 bytes at one time in the while, only the last <= 512 bytes can not be returned and it hangs there (channel_read()).
It looks like this issue is related to Windows powershell script, if I execute a normal Windows command through libssh remotely, the result can always be returned correctly, but as long as I execute a powershell script, that issue happens. It looks like channel_read() waits there for data, but there is no enough data to read and no EOF.
