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

Getting error string from a failed ssh command


Hello libssh list,

If I run a command over ssh that fails from the Linux command line:

normg@moop>ssh hood foo
bash: foo: command not found
normg@moop>echo $?
127


I get an error string ("bash: foo: command not found") and an error code (127). For example:
My question is how to do the equivalent with libssh ?
If I do this after opening a session and a channel:

int rc = ssh_channel_request_exec(sshChannel, "foo");
int bytesReady = ssh_channel_poll_timeout(sshChannel, timeout, FALSE);

returns -127 and:

int numRead = ssh_channel_read_timeout(sshChannel,
                             resultBuffer.nextWriteByte(),
                             (int) resultBuffer.bytesFree(),
                             0, // timeout: block in poll, not here
                             0);

returns 0, so I don't get the error string back from libssh.
How can I get the error string result from the failed command using libssh ?

Norm Green

P.S.: If the command succeeds (rc == 0) then everything works and I get the result string back as expected.






Follow-Ups:
Re: Getting error string from a failed ssh commandJakub Jelen <jjelen@xxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org