Perl Expected Score

I use Expect in perl to connect to a remote computer and perform certain functions. sample code is similar to

$outfile="ls -lrt"; $outfile1="output"; $exp->expect(30,-re,".*bash-.*" => sub{$exp->send("$outfile2 >$outfile \r")}); $exp->expect(60,-re,".*bash-.*" => sub{$exp->send("$shayam > $Ram \r")}); 

Even if the first expression fails, it will wait 60 seconds and execute the second statement. I just want to check that if only the first statement passes, it should continue.

+4
source share
1 answer

I assume that you are using the Expect.pm module described here . As indicated there:

If the call in the context of the expect () array returns ($ matched_pattern_position, $ error, $ Successfully_matching_string, $ before_match and $ after_match).

Thus, you probably want to call it in the context of the array, so that you can get an error, both when re-expressing and when transferring unsuccessfully.

 my ($matched_pattern_position, $error, $successfully_matching_string, $before_match, $after_match) = $exp->expect(30 , -re,".*bash-.*" => sub{$exp->send("$outfile2 >$outfile \r")} ); $exp->expect(60 ,-re,".*bash-.*" => sub{$exp->send("$shayam > $Ram \r")} ) if !defined $error; 
+4
source

Source: https://habr.com/ru/post/1315916/


All Articles