1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-08-07 08:02:55 +03:00

Fix exec example which has broken read usage

This commit is contained in:
Aris Adamantiadis
2010-03-28 21:49:17 +02:00
parent d2bb97c1c6
commit d7c1384df0

View File

@@ -7,7 +7,7 @@
int main(void) {
ssh_session session;
ssh_channel channel;
ssh_buffer buf;
char buf[4096];
int rc;
session = connect_ssh("localhost", NULL, 0);
@@ -38,24 +38,14 @@ int main(void) {
return 1;
}
if (channel_is_open(channel)) {
while (channel_poll(channel, 0) >= 0) {
buf = buffer_new();
rc = channel_read_buffer(channel, buf, 0, 0);
if (rc < 0) {
buffer_free(buf);
channel_close(channel);
ssh_disconnect(session);
ssh_finalize();
return 1;
do {
if (channel_is_open(channel)) {
rc = channel_read(channel, buf, sizeof(buf), 0);
if(rc > 0){
fwrite(buf,1,rc,stdout);
}
printf("%s\n", (char *) buffer_get(buf));
buffer_free(buf);
}
}
} while(rc > 0);
channel_send_eof(channel);
channel_close(channel);