Note that there are some explanatory texts on larger screens.

plurals
  1. POPerl Net::SSH doesn't receive prompts
    text
    copied!<p>I am writing a script to communicate with a remote server. I understand how to send a basic shell command such as "ls" or "find / |grep foo". But I am executing an interactive application at the other end.</p> <p>If I call $ssh->shell, I get the prompt from the remote server so I know that SSH is receiving this prompt. But then I can't do anything because the script is blocked in a shell.</p> <p>I installed two handlers. If I use the script to connect to a basic ssh host, and execute a shell command, the response is delivered to the handlers, so I know they are ok. So I expected the prompt from the application I am executing to be sent to these but it isn't.</p> <pre><code>#!/usr/bin/perl -w use strict; use Net::SSH::Perl; my $host = 'rt.olsendata.com'; my $user = 'rtdemo'; my $pass = 'rtdemo'; my %params = ('debug' =&gt; 1,'protocol' =&gt; 2); my $ssh = Net::SSH::Perl-&gt;new($host, %params); $ssh-&gt;register_handler("stderr", sub{ my ($ssh, $packet) = @_; receiveerrors($packet); }); $ssh-&gt;register_handler("stdout", sub{ my ($ssh, $packet) = @_; receivedata($packet); }); my ($output, $errors, $exit) = $ssh-&gt;login($user, $pass); </code></pre> <p>At this point I need to respond to the prompt by sending a "1". But this is interpreted by the remote host as a shell command, not a response to the prompt. It returns the error "h: 1: No such file or directory".</p> <p>If you want to try it you can use the demo ssh account at the top of the code. It is publicly available.</p> <p>Edit: I realise that Expect solves this issue, but I could not find any equivalent to register_handler() in Expect. Am I right in this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload