#!/usr/bin/perl -w use strict; use Expect; $|++; open STDERR, "/dev/null"; my $username="testuser"; my $password="password"; my $host="localhost"; my $timeout=5; my $exp = new Expect; $exp->log_file(undef); print "Content-type: text/html\n\n"; telnet_login($username,$password,$host,\$exp); $exp->expect($timeout, ['ncorrect', sub { print "
\n"; } } sub telnet_login { my ($username, $password, $host, $exp) = @_; $$exp->raw_pty(1); #treat this terminal as a raw file $$exp->log_stdout(0); #do not show terminal output to STD Out $$exp->spawn("/usr/bin/telnet $host") || die "Cannot open telnet\n"; $$exp->expect(7, ['ogin:', sub { $$exp->send("$username\n"); exp_continue; } ], ['assword:', sub { $$exp->send("$password\n"); } ], [timeout => sub { die "