Subject: Problem writting output to a file

Problem writting output to a file

From: vicent roca daniel <saptah_at_gmail.com>
Date: Sun, 18 Dec 2011 18:58:22 +0100

Hi Guys,
First of all, I'm sorry if this is not a libssh2 related question, but I'm
stuck on this error for two day and I'm desperate :(

I'm trying to write the output of a command exectution using libssh2 to a
file: Some code:

/*** definitions, etc...***/

sprintf(filename, "/tmp/.aom/%d-%s.json", epoch, host);
filefinal = fopen(filename, "w");

/* execute the command...*/

char buffer2[1024*4];

    while( (read = libssh2_channel_read( channel, buffer2,
sizeof(buffer2))) != 0 )
    {

        //buffer2[read-1] = '\0';
        fwrite(buffer2, sizeof(char), read, filefinal);

    }

/* closing the file ,etc...*/

The problem here is tha if this loop iterates only one time, I get some
extra data at the end of the file.
I've check that I read and write the same amount of bytes.+

I'm totally lost... any pointers?
Thank you :)

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2011-12-18