in reply to telnet with keypress and errmsg problem

Notes on timeout:
#start input of commands in telnet #---------------------------------- $|=1; use Net::Telnet; $telnet=new Net::Telnet; $telnet->port(25); $telnet->open("localhost"); #$telnet->waitfor('/\# $/i'); warn "W220 follows\n"; $telnet->waitfor('/220/i'); $cmd="\n"; $telnet->print($cmd); #@output=$telnet->waitfor('/Press any key to continue \(Q to quit\)/') +; warn "W500 follows\n"; # @output is actually the chars from the mailserver following # code 220 excl. until code 500 incl. @output=$telnet->waitfor('/500/'); warn "Pc - (a 502 SMTP code, I'd assume)\n"; $telnet->print('c'); #virtually press c key #@output2=$telnet->waitfor('/\# $/i'); #push(@output,@output2); warn "O==".join("\n",@output,"")."==\n"; warn "Wtimeout follows\n"; # create a deliberate error for error logging # PJ waitfor will ALWAYS DIE ANYWAY -> USE e.g. eval{} # PJ a failed waitfor dies w/o something of interest in $fault, $? or +$! eval{ warn "1", $fault=$telnet->waitfor('/dfs=l,gdmgll<>ifdgoij$/i'); }; warn "2$?\n"; # unused by waitfor warn "3$!\n"; # unused by waitfor warn "4", do{$fault=$telnet->errmsg},"\n"; # pattern match timed-out $telnet->close; if ($fault ne "") { print "you got an error $fault\n"; }

The output for me annoying a postfix mailer daemon is:

W220 follows W500 follows Pc - (a 502 SMTP code, I'd assume) O== anuurn.compact ESMTP Postfix (Ubuntu) 500 == Wtimeout follows 20 3 4pattern match timed-out you got an error pattern match timed-out