From: titetluc t. <tit...@gm...> - 2007-07-09 11:12:10
|
Hi all, I encoutered a problem using Expect version 1.20 but did not find any information in the mailing list The following code should display "failed" (the password is incorrect and Net::SSH::Expect::connect method raised an exception) but displays "succeeded" ################################ use strict; use Net::SSH::Expect; sub test { my $ssh; $ssh = Net::SSH::Expect->new(host => 'my_machine', prompt => 'my_prompt', password => 'wrong_password', user => 'titouan', timeout => 4); $ssh->connect(); } eval { test(); }; if ($@){ print "failed\n"; } else { print "succeeded\n"; } ################################ If I modify the code (by declaring the $ssh variable out of the test function), the code displays failed ################################ use strict; use Net::SSH::Expect; my $ssh; sub test { $ssh = Net::SSH::Expect->new(host => 'my_machine', prompt => 'my_prompt', password => 'wrong_password', user => 'titouan', timeout => 4); $ssh->connect(); } eval { test(); }; if ($@){ print "failed\n"; } else { print "succeeded\n"; } ################################ I tried to understand what happened in the first case If I use the debugger, the $@ is correctly set with the Net::SSH::Expect module, but when ssh variable is out of scope, the perl interpeter call the Expect::DESTROY function. This last function undef $@ (when calling $self->hard_close()) Is this a bug in Expect module ? How can I prevent this behavior ? Thanks |