Escape character is '^]'. Ubuntu 8.04.1 scriptbed login: $VAR1 = bless( \*Symbol::GEN0, 'Expect' ); scriptbed Password: $VAR1 = [ bless( \*Symbol::GEN0, 'Expect' ) ]; Can't call method "do_soft_close" on unblessed reference at ./myexpect.pl line 57. #### #!/usr/bin/perl -w 2 3 BEGIN { 4 unshift(@INC,'/n/home5/release/Perl/Modules/lib/perl5/site_perl/5.8.0'); 5 } 6 7 use strict; 8 use Expect; 9 use Data::Dumper; 10 11 my $timeout = 1; 12 13 my $username = 'scriptbed'; 14 my $password = 'invalid'; # forcing the timeout 15 16 print localtime(time)."\n"; 17 18 my $exp = Expect->spawn('/usr/bin/telnet','scriptbed'); 19 20 my $spawn_ok; 21 $exp->expect($timeout, 22 [ 23 qr'login: $', 24 sub { 25 $spawn_ok = 1; 26 my $fh = shift; 27 print Dumper $fh; 28 $fh->send("$username\n"); 29 exp_continue; 30 } 31 ], 32 [ 33 'Password: $', 34 sub { 35 my $fh = shift; 36 print $fh "$password\n"; 37 exp_continue; 38 } 39 ], 40 [ 41 eof => 42 sub { 43 my $fh = shift; 44 $fh->do_soft_close(); 45 if ($spawn_ok) { 46 die "ERROR: premature EOF in login.\n"; 47 } else { 48 die "ERROR: could not spawn telnet.\n"; 49 } 50 } 51 ], 52 [ 53 timeout => 54 sub { 55 my $fh = shift; 56 print Dumper $fh; 57 $fh->do_soft_close(); 58 die "Timed out\n"; 59 } 60 ], 61 '-re', qr'[#>:] $', #' wait for shell prompt, then exit expec t 62 );