[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting mkdir command result


Hi Nikhil,

Glad you solved your problem. Beware that ssh_channel_request_exec will
always return SSH_OK if the command was possibly executed on the server
(and not denied by the SSH server). It does not ensure that the command
succeeded, since this may take some time to know, and
ssh_channel_request_exec returns well before the command execution has
been finished (otherwise you wouldn't be able to interact with the
command with channels).

Kr,

Aris

Le 12/01/11 10:43, Nikhil Agrawal a écrit :
> When using ssh_channel_request_exec, it always returned success even if
> mkdir fails and no error identified in ssh_get_error.
> 
> But setting stderr to 1 and parsing returned buffer, resolves my problem.
> 
> Many Thanks!
> 
> Regards,
> Nikhil
> 
> On Wed, Jan 12, 2011 at 2:35 PM, Aris Adamantiadis <aris@xxxxxxxxxxxx
> <mailto:aris@xxxxxxxxxxxx>> wrote:
> 
>     Le 12/01/11 08:08, Nikhil Agrawal a écrit :
>     > Hi,
>     >
>     > I am using libssh to run mkdir on remote machine. In case mkdir
>     fails, I
>     > want to receive/get error in my client so i can take measures. I am
>     > getting OK as return code in all cases and don’t get to know if mkdir
>     > successfully ran or not. Please Suggest.
>     >
>     > Thanks!
>     >
>     >
>     Hi Nikhil,
> 
>     I suggest that you check the return code, either using Rocky's method,
>     or by using ssh_channel_get_exit_status() (you may have to wait that the
>     channel is closed for this).
>     You can check in the stderr stream
>     (ssh_channel_read(channel,dest,len,1); since the error message of mkdir
>     will be written to stderr and not stdout.
> 
>     Another solution, that I really advise you use, is to use the sftp
>     subsystem which has reliable functions to manipulate remote filesystems.
> 
>     Kind regards,
> 
>     Aris
> 
> 


References:
Getting mkdir command resultNikhil Agrawal <mrnikhilagrawal@xxxxxxxxx>
Re: Getting mkdir command resultAris Adamantiadis <aris@xxxxxxxxxxxx>
Re: Getting mkdir command resultNikhil Agrawal <mrnikhilagrawal@xxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org