mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-08-08 19:02:06 +03:00
Fix exec example which has broken read usage
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
int main(void) {
|
int main(void) {
|
||||||
ssh_session session;
|
ssh_session session;
|
||||||
ssh_channel channel;
|
ssh_channel channel;
|
||||||
ssh_buffer buf;
|
char buf[4096];
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
session = connect_ssh("localhost", NULL, 0);
|
session = connect_ssh("localhost", NULL, 0);
|
||||||
@@ -38,24 +38,14 @@ int main(void) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
if (channel_is_open(channel)) {
|
if (channel_is_open(channel)) {
|
||||||
while (channel_poll(channel, 0) >= 0) {
|
rc = channel_read(channel, buf, sizeof(buf), 0);
|
||||||
buf = buffer_new();
|
if(rc > 0){
|
||||||
rc = channel_read_buffer(channel, buf, 0, 0);
|
fwrite(buf,1,rc,stdout);
|
||||||
if (rc < 0) {
|
|
||||||
buffer_free(buf);
|
|
||||||
channel_close(channel);
|
|
||||||
ssh_disconnect(session);
|
|
||||||
ssh_finalize();
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%s\n", (char *) buffer_get(buf));
|
|
||||||
|
|
||||||
buffer_free(buf);
|
|
||||||
}
|
}
|
||||||
}
|
} while(rc > 0);
|
||||||
|
|
||||||
channel_send_eof(channel);
|
channel_send_eof(channel);
|
||||||
channel_close(channel);
|
channel_close(channel);
|
||||||
|
Reference in New Issue
Block a user