in reply to Perl Expect module
#!/usr/bin/perl use strict; use Expect; my $session = new Expect; $session->spawn("/usr/bin/bash"); # clear buffer $session->expect(20, -re, "."); $session->clear_accum(); # cd to required dir print $session "cd \/home\/homedir\r"; $session->expect(90, -re, "bash"); # wait sleep 20; # get the results of the command and assign them to an array print $session "ls \-altr\r"; my @array = $session->expect(60, -re, "bash"); $session->clear_accum; my @array1 = split('\n', $array[3]); # print out each element of the array so that they can be further proc +essed for (my $i = 0; $i <= $#array1; $i++) { print "\nElement $i is\n$array1[$i]\n"; }
|
|---|