[Libssh] channel_read - Save read characters in "string"

Aris Adamantiadis aris at 0xbadc0de.be
Mon Jun 30 00:43:40 CEST 2008


Ah yep. buffer_get is a void * because there is no reason you would read 
only character data. It works fine in C but c++ needs explicite casting.
command_output.assign((const char *) 
buffer_get(readbuf),buffer_get_len(readbuf));

Regards,
Aris
Rico Kerster a écrit :
> Thanks for the fast reply
> 
> Tried it with 
> command_output.assign(buffer_get(readbuf),buffer_get_len(readbuf));
> 
> Though I get the following compiler error:
> error: call of overloaded 'assign(void*, int)' is ambiguous|
> 
> I don't see how the first parameter can be a void*.
> 
> I really appreciate your effort and look forward to the new release.
> 
> Rico Kerster
> 
> 
>> Date: Mon, 30 Jun 2008 00:19:33 +0200
>> From: aris at 0xbadc0de.be
>> To: libssh at cerkinfo.be
>> Subject: Re: [Libssh] channel_read - Save read characters in "string"
>>
>> Rico Kerster a écrit :
>>> Hello libssh-List
>>> I successfully logged into my SSH server, can issue a command and output the comands' result to the terminal window (as in the example, I achieved that with the function "write()")
>>>
>>> string command_output;
>>> char cmd[] = "date\n";
>>> BUFFER *readbuf = buffer_new();
>>> int num = channel_write(channel,cmd,sizeof(cmd));
>>> num = channel_read(channel,readbuf,0,0);
>>>
>>> write(1,buffer_get(readbuf),buffer_get_len(readbuf));
>>>
>>> But now I'd like to store the content of readbuf in the string "command_output", I studied the _M_write() template and how "write()" gets out the characters but I couldn't manage to understand and copy it. So to sum up my question:
>>>
>>> How do I store the characters of readbuff (BUFFER) in command_output (string) or in a char[]?
>>>
>>> Thanks in Advance.
>>>
>> Hello,
>>
>> Consider the output of buffer_get like a char [] type string, except it
>> is not nul terminated.
>> http://www.cplusplus.com/reference/string/string/assign.html
>> Look at string::assign(const char *s, size_t n);
>>
>> I's much like a C++ problem you've got. The next release of libssh will
>> have a more classical channel_read() which won't require a BUFFER object.
>>
>> Regards,
>> Aris
>>
>> _______________________________________________
>> Libssh mailing list
>> Libssh at cerkinfo.be
>> http://www.cerkinfo.be/cgi-bin/mailman/listinfo/libssh
> 
> _________________________________________________________________
> Die aktuelle Frühjahrsmode - Preise vergleichen bei MSN Shopping
> http://shopping.msn.de/category/damenbekleidung/bcatid66/forsale?text=category:damenbekleidung&edt=1&ptnrid=230
> _______________________________________________
> Libssh mailing list
> Libssh at cerkinfo.be
> http://www.cerkinfo.be/cgi-bin/mailman/listinfo/libssh




More information about the Libssh mailing list