Pavel Strashkin | 5 Oct 2011 23:23
Picon

How do i know that process has completed?

Hello,

1. For an example i'm trying to create a directory or whatever. I
create session, channel, do exec ("mkdir ...").What is the best way to
know that command has completed and exit_status is ready to be read?

2. Is there any way to read stdout/stderr separately?

Thank you!
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel

Peter Stuge | 5 Oct 2011 23:27
Picon

Re: How do i know that process has completed?

Pavel Strashkin wrote:
> What is the best way to know that command has completed and
> exit_status is ready to be read?

libssh2_channel_eof()

> 2. Is there any way to read stdout/stderr separately?

libssh2_channel_read() reads stdout
libssh2_channel_read_stderr() guess what ;)

//Peter
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel

Pavel Strashkin | 5 Oct 2011 23:42
Picon

Re: How do i know that process has completed?

Am i correct that libssh2_channel_eof should be used with
libssh2_channel_read? i.e. without reading from a channel EOF will
never be received.

2011/10/5 Peter Stuge <peter@...>:
> Pavel Strashkin wrote:
>> What is the best way to know that command has completed and
>> exit_status is ready to be read?
>
> libssh2_channel_eof()
>
>
>> 2. Is there any way to read stdout/stderr separately?
>
> libssh2_channel_read() reads stdout
> libssh2_channel_read_stderr() guess what ;)
>
>
> //Peter
> _______________________________________________
> libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
>
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel

Peter Stuge | 5 Oct 2011 23:45
Picon

Re: How do i know that process has completed?

Pavel Strashkin wrote:
> Am i correct that libssh2_channel_eof should be used with
> libssh2_channel_read? i.e. without reading from a channel EOF will
> never be received.

Well, EOF may have been received, but libssh2 will not tell you until
you have also read all data from both stdout and stderr.

//Peter
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel

Pavel Strashkin | 5 Oct 2011 23:52
Picon

Re: How do i know that process has completed?

Oh, so, for an example, if some application prints to stdout and
stderr both, and i'm reading _only_ from stdout (and waiting for EOF),
i can get stuck just because there is a data in stderr and i have to
read it, but i don't?

2011/10/5 Peter Stuge <peter@...>:
> Pavel Strashkin wrote:
>> Am i correct that libssh2_channel_eof should be used with
>> libssh2_channel_read? i.e. without reading from a channel EOF will
>> never be received.
>
> Well, EOF may have been received, but libssh2 will not tell you until
> you have also read all data from both stdout and stderr.
>
>
> //Peter
> _______________________________________________
> libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
>
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel

Peter Stuge | 5 Oct 2011 23:57
Picon

Re: How do i know that process has completed?

Pavel Strashkin wrote:
> Oh, so, for an example, if some application prints to stdout and
> stderr both, and i'm reading _only_ from stdout (and waiting for EOF),
> i can get stuck just because there is a data in stderr and i have to
> read it, but i don't?

Yes.

//Peter
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel

Steven Ayre | 6 Oct 2011 00:06
Picon

Re: How do i know that process has completed?

Pavel,

You can however choose to do a nonblocking read and then read from
both stdout and stderr. That'll return immediately if no data is
available so you won't get stuck on a read from stdout if there's no
data available.

libssh2_poll() can let you know that there's stdout(IN) and stderr
(EXT) data available, and that the command has finished
(CHANNEL_CLOSED). It's depreciated now though.

It seems the new idea is to do a select() or poll() on the socket,
then do a nonblocking read of both stdout and stderr. Can someone
clarify if that's correct please?

-Steve

On 5 October 2011 22:57, Peter Stuge <peter@...> wrote:
> Pavel Strashkin wrote:
>> Oh, so, for an example, if some application prints to stdout and
>> stderr both, and i'm reading _only_ from stdout (and waiting for EOF),
>> i can get stuck just because there is a data in stderr and i have to
>> read it, but i don't?
>
> Yes.
>
>
> //Peter
> _______________________________________________
> libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
(Continue reading)

Peter Stuge | 6 Oct 2011 00:15
Picon

Re: How do i know that process has completed?

Steven Ayre wrote:
> It seems the new idea is to do a select() or poll() on the socket,
> then do a nonblocking read of both stdout and stderr. Can someone
> clarify if that's correct please?

This is the only way it works yes. See example/direct_tcpip.c for an
example of how this can look. (This also considers another socket in
the same select() call.)

//Peter
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel


Gmane