in reply to SSH Command output
in thread Asynchronous Processing a command execution

Hi It had been really confusing , however I have managed to do asynchronous SSH output using SSH Perl module. Here is teh code extract
elsif (defined $pid) { close STDOUT; close STDERR; $ssh=Net::SSH::Perl->new("113.128.160.214"); $ssh->login($UNM,$Pass,'true'); $cmd="ls -l"; $ssh->register_handler(SSH_SMSG_STDOUT_DATA,sub{($ssh,$packetout)=@_;$ +cache->set($session,[0,$packetout->get_str])}); #$ssh->register_handler(SSH_SMSG_EXITSTATUS,sub{($ssh,$packetexit)=@_; +$cache->set($session,[1,$packetexit->get_str])}); ($stdout,$stderr,$exit)=$ssh->cmd($cmd);
The above code returns me the standard output from the command executed over SSH.I would also like to print messages like connecting to the remotebox ,any errors occured while connection.I tried Standard Error message constant . but it did not return me anything worthwhile. Please advise

Replies are listed 'Best First'.
Re^2: SSH Command output
by Alfaromeo (Initiate) on Jul 11, 2008 at 14:33 UTC
    close STDOUT; close STDERR; $ssh=Net::SSH::Perl->new("113.128.160.214"); $ssh->login($UNM,$Pass); $cmd="ping 114.9.36.142"; $ssh->register_handler(SSH_SMSG_STDOUT_DATA,sub{($ssh,$packetout)=@_;p +ush(@output,$packetout->get_str);$cache->set($session,[0,@output])}); #$ssh->register_handler(SSH_SMSG_EXITSTATUS,sub{($ssh,$packetexit)=@_; +$cache->set($session,[1,$packetexit->get_str])}); ($stdout,$stderr,$exit)=$ssh->cmd($cmd);
    The above code only prints for me the first 2 lines of the ping command after execution. What is wrong ?