Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^3: Net::SSH2 and Trapeze, in-band authentication

by salva (Abbot)
on Apr 05, 2013 at 08:18 UTC ( #1027099=note: print w/replies, xml ) Need Help??

in reply to Re^2: Net::SSH2 and Trapeze, in-band authentication
in thread Net::SSH2 and Trapeze, in-band authentication

I don't think the get_channel sub is reliable. If for whatever reason the data coming from the remote side is delayed, the non-blocking read call is going to return undef and any additional data will be lost.

Doing non-blocking IO with Net::SSH2 is far from being easy. You can see how it is done in my module Net::SSH::Any using select to check when new data arrives on the SSH socket (the code is here, see the __io3 method).

Another possibility that usually works is to send all the input data (login and commands) in one go and then capture everything in blocking mode until you get and EOF. You will have to add an additional command to close the connection from the remote side (i.e. exit).

Replies are listed 'Best First'.
Re^4: Net::SSH2 and Trapeze, in-band authentication
by FloydATC (Deacon) on Apr 05, 2013 at 12:07 UTC
    Yes, the data is indeed delayed and the non-blocking call does return undef every now and then. This is why I call get_channel() repeatedly from get_response() and accumulate the results until I see the prompt.

    The reason I can't do blocking calls is because the channel will never EOF or return a short buffer unless I tell the host to "exit" and terminate the connection. Not cool if I want to execute more commands based on the output from a previous command.

    -- Time flies when you don't know what you're doing

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1027099]
[Corion]: 5.14 is also a good target, widely available and fairly stable. Also, over five years old, which doesn't push people into a needless upgrade cycle
[Discipulus]: yes I saw your efforts Corion but the pain is worth?
[Corion]: Discipulus: IMO it's not that much pain, but most of the systems I use have a Perl 5.14 or newer on them nowadays
[marto]: the question is more, is Padre still the way new users should be directed?
[Discipulus]: ah ah I have all 5.26 atm but I play alone..
[Corion]: Except this RHEL box, which comes with Perl 5.10.1 , but there I installed my own 5.20.3 for the real Perl programs we run ;)
[Corion]: marto: I used Padre for some time but then switched to Notepad++, since all the funky features I wanted to put into Padre couldn't be made to work, and/or I lost interest :)
[Discipulus]: indeed marto I dunno. I tested once and many years ago. But I'm not the programmer yardstick. I try to install Padre via cpan now just to add a line about it in the issue. Strawberryperl all life long!
[marto]: yeah, when I worked on Windows I did use Np++ all the time

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (12)
As of 2018-06-25 08:54 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.