in reply to Re^2: Perl Expect
in thread Perl Expect

When posting put code inside <code>...</code> tags, please. Otherwise it is quite hard to read.

What is that nicetelnet thing? using a too clever telnet client my get in the way.

Replies are listed 'Best First'.
Re^4: Perl Expect
by Anonymous Monk on Jan 18, 2018 at 05:23 UTC

    nicetelnet is just a wrapper on top of telnet. reposing the code.

    #!/usr/bin/perl use strict; use Expect; my $session = new Expect; $session->spawn("telnet $my_ip"); $session->expect(90, -re, "login:"); print $session "regress\r"; $session->expect(90, -re, "Password:"); print $session "MaRtInI\r"; $session->expect(90, -re, ".*"); print $session "pwd\r"; $session->expect(90, -re, ".*"); $session->close()
      Expect provides several methods for retrieving the matching data and also the last error. Have you experimented with them? Expect should be able to detect the slave process has terminated and report it accordingly.

      You could also try Net::Telnet. That module doesn't depend on an intermediate program and shouldn't have any problem detecting a remote closed connection (in case Expect has any).