u235sentinel has asked for the wisdom of the Perl Monks concerning the following question:

Dear PerlMonks,

I've been loving Net::SSH2 and have been using it for a few months. It's much easier to install (less dependancies than Net::SSH::Perl) and overall it's faster when hitting our remote servers. I've been working with the Net::SSH2 forum however they seem to have problems with their server lately. I'm hoping someone here might have some insights to help me along my way.

The Question/Problem

I'm trying to pull STDERR from my remote server. The idea is we want to trigger a subroutine to execute when STDERR traffic is detected. In the past I simply called the NET::SSH::Perl method register_handler. Here is how I used to do it
&register_handler("STDERR", sub { my($channel, $buffer) = @_; print "** STDERR -- I received this: ", $buffer->byt +es; });
Dave Robins (the developer) mentioned I check out the POLL method to do something similar to this however I must be missing something. I've read perldoc however I'm not seeing where to call the subroutine from POLL. Here is the module I'm using Net-SSH2-0.09

Here is how I'm trying to call it:

# Create the ssh2 object my $ssh2 = Net::SSH2->new(); # Create my STDERR trigger my $poll=Net::SSH2->poll( 1, 'pollerr'); # connect to remote server $ssh2->connect($server) or die "** Failed to connect via Net::SSH2: + $!\n"; print "** Connect to server $server successful\n\n";
I've tried replacing 'pollerr' with STDERR and stderr. In both cases I get a message stating I can't use symbolic references. Only hard references are allowed.

Has anyone been successful in doing this? I'm also curious how I could use POLL to execute a subroutine when STDERR traffic is detected.

I've also tried using Net::SSH::Channel and calling the read method to read STDERR. It runs fine however nothing is captured when I run my sudo command. I've even tried the above against STDOUT just to see if I'm getting anything. No dice.

What else can I tell you about my situation?

Thanks a bunch!

Replies are listed 'Best First'.
Re: Using Net::SSH2 to read remote STDERR channel
by zentara (Cardinal) on Oct 03, 2006 at 19:07 UTC
    This is a bit over my head, but go to http://groups.google.com and search for "Net::SSH2 poll stderr". There are a couple of POE scripts there that might help. POE NetSsh2 component

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: Using Net::SSH2 to read remote STDERR channel
by Khen1950fx (Canon) on Oct 03, 2006 at 21:36 UTC
    There's an example of poll in the docs for Net::SSH2::Channel. You can find it under "sub GETC". See:

    sub GETC