diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2009-12-24 10:46:46 +0100 |
---|---|---|
committer | Aris Adamantiadis <aris@0xbadc0de.be> | 2009-12-24 10:46:46 +0100 |
commit | bfdc48e320143183927933c23f43ff87def798f3 (patch) | |
tree | 3d781e0347fe490c29b5e455dc87ef4f180d1b72 | |
parent | fcda8beb1cbf3e30263fe566bfef625555bdd897 (diff) | |
download | libssh-bfdc48e320143183927933c23f43ff87def798f3.tar.gz libssh-bfdc48e320143183927933c23f43ff87def798f3.tar.xz libssh-bfdc48e320143183927933c23f43ff87def798f3.zip |
Simplification of the "exec" sample
-rw-r--r-- | examples/exec.c | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/examples/exec.c b/examples/exec.c index 077b94f..eed7586 100644 --- a/examples/exec.c +++ b/examples/exec.c @@ -7,7 +7,7 @@ int main(void) { ssh_session session; ssh_channel channel; - ssh_buffer buf; + char buffer[256]; int rc; session = connect_ssh("localhost", NULL, 0); @@ -18,7 +18,6 @@ int main(void) { channel = channel_new(session);; if (channel == NULL) { ssh_disconnect(session); - ssh_finalize(); return 1; } @@ -26,7 +25,6 @@ int main(void) { if (rc < 0) { channel_close(channel); ssh_disconnect(session); - ssh_finalize(); return 1; } @@ -34,34 +32,24 @@ int main(void) { if (rc < 0) { channel_close(channel); ssh_disconnect(session); - ssh_finalize(); 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; - } - - printf("%s\n", (char *) buffer_get(buf)); - - buffer_free(buf); - } + while ((rc = channel_read(channel, buffer, sizeof(buffer), 0)) >= 0) { + fwrite(buffer, 1, rc, stdout); + } + + if (rc < 0) { + channel_close(channel); + ssh_disconnect(session); + return 1; } channel_send_eof(channel); channel_close(channel); ssh_disconnect(session); - ssh_finalize(); return 0; } |