Re: [Ssh-sftp-perl-users] Problem getting output using Net::SSH2
Brought to you by:
dbrobins
From: Steve P. <st...@fo...> - 2011-05-06 03:32:05
|
On 6/05/2011 12:55 PM, David Robins wrote: > The problem with waiting for responses from a command shell channel is that it's no different from any other channel and one cannot intrinsically tell the difference between no response due to a command being busy or slow and no response due to the output being finished. The 250ms timeout is in Net::SSH2::Channel::GETC (READLINE depends on GETC, and READLINE is what is implementing<>). You can get more control over reading from the channel with the read method - but less convenience. Similarly you can use the Net::SSH2::poll method on your own to check for pending events (and give it a timeout), again, at a cost of convenience. > > To avoid requiring a 1 second sleep before getting each line, you could poll the channel with a 1000ms timeout and then read a line if it indicates data being ready; this means you only wait a whole second in the end of output case (assuming 1000 ms is long enough for your command). To eliminate that last case you could either exec a single command (see Net::SSH2::Channel::exec) which should terminate the poll invocation when the command exits, or send something like "cmd; exit" to the shell channel to have it exit after the command runs. Thanks for the replies, I've since implemented a while loop that waits for the first line of output then continues for the rest, this also lets me implement a timeout where the command takes an inordinate amount of time I can exit the script with a timeout error as well. I'll look more into the Net::SSH2::Channel:Exec stuff as well as that looks quite promising. Thanks, -- Steve. |